/// <summary>
        /// Constructs internal context for Pkcs11Token class
        /// </summary>
        /// <param name="slotContext">Internal context for Pkcs11Slot class</param>
        /// <returns>Internal context for Pkcs11Token class</returns>
        private Pkcs11TokenContext GetTokenContext(Pkcs11SlotContext slotContext)
        {
            var     tokenInfo     = new Pkcs11TokenInfo(slotContext.Slot.GetTokenInfo());
            Session masterSession = (!tokenInfo.Initialized) ? null : slotContext.Slot.OpenSession(SessionType.ReadOnly);

            return(new Pkcs11TokenContext(tokenInfo, masterSession, slotContext));
        }
        /// <summary>
        /// Creates new instance of Pkcs11Token class
        /// </summary>
        /// <param name="slotContext">Internal context for Pkcs11Slot class</param>
        internal Pkcs11Token(Pkcs11SlotContext slotContext)
        {
            if (slotContext == null)
            {
                throw new ArgumentNullException(nameof(slotContext));
            }

            _tokenContext = this.GetTokenContext(slotContext);
            // Note: _certificates are loaded on first access
        }
Пример #3
0
        /// <summary>
        /// Creates new instance of Pkcs11Slot class
        /// </summary>
        /// <param name="slot">High level PKCS#11 slot</param>
        /// <param name="storeContext">Internal context for Pkcs11X509Store class</param>
        internal Pkcs11Slot(ISlot slot, Pkcs11X509StoreContext storeContext)
        {
            if (slot == null)
            {
                throw new ArgumentNullException(nameof(slot));
            }

            if (storeContext == null)
            {
                throw new ArgumentNullException(nameof(storeContext));
            }

            _slotContext = this.GetSlotContext(slot, storeContext);
            _token       = this.GetToken();
        }
Пример #4
0
 /// <summary>
 /// Creates new instance of Pkcs11TokenContext class
 /// </summary>
 /// <param name="tokenInfo">Detailed information about PKCS#11 token (cryptographic device)</param>
 /// <param name="authenticatedSession">High level PKCS#11 session that holds authenticated state of the token</param>
 /// <param name="slotContext">Internal context for Pkcs11Slot class</param>
 internal Pkcs11TokenContext(Pkcs11TokenInfo tokenInfo, ISession authenticatedSession, Pkcs11SlotContext slotContext)
 {
     _tokenInfo            = tokenInfo ?? throw new ArgumentNullException(nameof(tokenInfo));
     _authenticatedSession = authenticatedSession;
     _slotContext          = slotContext ?? throw new ArgumentNullException(nameof(slotContext));
 }