Ejemplo n.º 1
0
        /// <summary>
        /// Obtains a list of mechanism types supported by a token
        /// </summary>
        /// <returns>List of mechanism types supported by a token</returns>
        public List <CKM> GetMechanismList()
        {
            _logger.Debug("Slot({0})::GetMechanismList", _slotId);

            NativeULong mechanismCount = 0;
            CKR         rv             = _pkcs11Library.C_GetMechanismList(_slotId, null, ref mechanismCount);

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

            if (mechanismCount < 1)
            {
                return(new List <CKM>());
            }

            CKM[] mechanismList = new CKM[mechanismCount];
            rv = _pkcs11Library.C_GetMechanismList(_slotId, mechanismList, ref mechanismCount);
            if (rv != CKR.CKR_OK)
            {
                throw new Pkcs11Exception("C_GetMechanismList", rv);
            }

            if (mechanismList.Length != ConvertUtils.UInt32ToInt32(mechanismCount))
            {
                Array.Resize(ref mechanismList, ConvertUtils.UInt32ToInt32(mechanismCount));
            }

            return(new List <CKM>(mechanismList));
        }