Ejemplo n.º 1
0
        /// <summary>
        /// Obtains a list of unmanaged struct sizes.
        /// This method should be used only for testing purposes with PKCS11-MOCK module.
        /// </summary>
        /// <param name="pkcs11">Instance of the extended class</param>
        /// <returns>List of unmanaged struct sizes</returns>
        public static List <ulong> GetUnmanagedStructSizeList(this HLA80.Pkcs11 pkcs11)
        {
            if (pkcs11.Disposed)
            {
                throw new ObjectDisposedException(pkcs11.GetType().FullName);
            }

            ulong sizeCount = 0;
            CKR   rv        = pkcs11.LowLevelPkcs11.C_GetUnmanagedStructSizeList(null, ref sizeCount);

            if (rv != CKR.CKR_OK)
            {
                throw new Pkcs11Exception("C_GetUnmanagedStructSizeList", rv);
            }

            ulong[] sizeList = new ulong[sizeCount];
            rv = pkcs11.LowLevelPkcs11.C_GetUnmanagedStructSizeList(sizeList, ref sizeCount);
            if (rv != CKR.CKR_OK)
            {
                throw new Pkcs11Exception("C_GetUnmanagedStructSizeList", rv);
            }

            if (sizeList.Length != Convert.ToInt32(sizeCount))
            {
                Array.Resize(ref sizeList, Convert.ToInt32(sizeCount));
            }

            return(new List <ulong>(sizeList));
        }