Exemplo n.º 1
0
        /// <summary>
        /// Creates a permission that is the union of the current permission and the specified permission.
        /// </summary>
        /// <param name="target">A permission to combine with the current permission. It must be the same type as the current permission.</param>
        /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
        /// <exception cref="ArgumentException"><i>target</i> is not of the same type as the current permission.</exception>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            SmartcardPermission permission = target as SmartcardPermission;

            if (permission == null)
            {
                throw new ArgumentException(ResourceController.GetString("Error_ParamInvalid"));
            }
            SmartcardPermission retPerm = new SmartcardPermission((this.IsUnrestricted() || permission.IsUnrestricted()) ? SmartcardConnectOption.Unrestricted : this.m_Options, this.m_AllowedAtrs);

            if (!retPerm.IsUnrestricted())
            {
                foreach (Atr a in permission.m_AllowedAtrs)
                {
                    if (!retPerm.m_AllowedAtrs.Contains(a))
                    {
                        retPerm.m_AllowedAtrs.AddLast((Atr)a.Clone());
                    }
                }
                if ((permission.IsEmpty() && this.IsEmpty()))
                {
                    retPerm.m_Options = SmartcardConnectOption.None;
                }
                else
                {
                    retPerm.m_Options = SmartcardConnectOption.AllowedAtrs;
                }
            }
            return(retPerm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the current permission is a subset of the specified permission.
        /// </summary>
        /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be the same type as the current permission.</param>
        /// <returns><b>true</b> if the current permission is a subset of the specified permission; otherwise, <b>false</b>.</returns>
        /// <exception cref="ArgumentException"><i>target</i> is not of the same type as the current permission.</exception>
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.IsEmpty());
            }
            SmartcardPermission permission = target as SmartcardPermission;

            if (permission == null)
            {
                throw new ArgumentException(ResourceController.GetString("Error_ParamInvalid"));
            }
            if (permission.IsUnrestricted() || this.IsEmpty())
            {
                return(true);
            }
            if (this.IsUnrestricted() || permission.IsEmpty())
            {
                return(false);
            }
            // if we get here, both permissions are set to 'AllowedAtrs'
            foreach (Atr a in this.m_AllowedAtrs)
            {
                if (!permission.m_AllowedAtrs.Contains(a))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and returns a permission that is the intersection of the current permission and the specified permission.
        /// </summary>
        /// <param name="target">A permission to intersect with the current permission. It must be the same type as the current permission. </param>
        /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is a null reference if the intersection is empty.</returns>
        /// <exception cref="ArgumentException"><i>target</i> is not of the same type as the current permission.</exception>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }
            SmartcardPermission permission = target as SmartcardPermission;

            if (permission == null)
            {
                throw new ArgumentException(ResourceController.GetString("Error_ParamInvalid"));
            }
            if (this.IsUnrestricted() || permission.IsEmpty())
            {
                return(permission.Copy());
            }
            if (permission.IsUnrestricted() || this.IsEmpty())
            {
                return(this.Copy());
            }
            // if we get here, both permissions are set to 'AllowedAtrs'
            SmartcardPermission retPerm = new SmartcardPermission(SmartcardConnectOption.AllowedAtrs);

            foreach (Atr a in this.m_AllowedAtrs)
            {
                if (permission.m_AllowedAtrs.Contains(a))
                {
                    retPerm.m_AllowedAtrs.AddLast(a);
                }
            }
            if (retPerm.m_AllowedAtrs.Count == 0)
            {
                retPerm.m_Options = SmartcardConnectOption.None;
            }
            return(retPerm);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Connects to the card in the smartcard reader.
 /// </summary>
 /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
 /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public void Connect(SmartcardShare share, SmartcardProtocols protocol) {
     if (m_Disposed)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (m_Card != IntPtr.Zero)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardAlreadyConnected"));
     int ret = NativeMethods.SCardConnect(m_Context, m_ReaderName, (int)share, (int)protocol, out m_Card, out m_ActiveProtocol);
     if (ret != NativeMethods.SCARD_S_SUCCESS)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardConnect"), ret);
     // make sure the user has at least the 'AllowedAtrs' option of the SmartcardPermission
     // for the current ATR
     try {
         SmartcardPermission permission = new SmartcardPermission(new Atr[] { Atr });
         permission.Demand();
     } catch {
         Dispose();
         throw;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates a permission that is the union of the current permission and the specified permission.
 /// </summary>
 /// <param name="target">A permission to combine with the current permission. It must be the same type as the current permission.</param>
 /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns>
 /// <exception cref="ArgumentException"><i>target</i> is not of the same type as the current permission.</exception>
 public override IPermission Union(IPermission target) {
     if (target == null)
         return this.Copy();
     SmartcardPermission permission = target as SmartcardPermission;
     if (permission == null)
         throw new ArgumentException(ResourceController.GetString("Error_ParamInvalid"));
     SmartcardPermission retPerm = new SmartcardPermission((this.IsUnrestricted() || permission.IsUnrestricted()) ? SmartcardConnectOption.Unrestricted : this.m_Options, this.m_AllowedAtrs);
     if (!retPerm.IsUnrestricted()) {
         foreach (Atr a in permission.m_AllowedAtrs) {
             if (!retPerm.m_AllowedAtrs.Contains(a)) {
                 retPerm.m_AllowedAtrs.AddLast((Atr)a.Clone());
             }
         }
         if ((permission.IsEmpty() && this.IsEmpty()))
             retPerm.m_Options = SmartcardConnectOption.None;
         else
             retPerm.m_Options = SmartcardConnectOption.AllowedAtrs;
     }
     return retPerm;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates and returns a permission that is the intersection of the current permission and the specified permission.
 /// </summary>
 /// <param name="target">A permission to intersect with the current permission. It must be the same type as the current permission. </param>
 /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is a null reference if the intersection is empty.</returns>
 /// <exception cref="ArgumentException"><i>target</i> is not of the same type as the current permission.</exception>
 public override IPermission Intersect(IPermission target) {
     if (target == null) {
         return null;
     }
     SmartcardPermission permission = target as SmartcardPermission;
     if (permission == null) {
         throw new ArgumentException(ResourceController.GetString("Error_ParamInvalid"));
     }
     if (this.IsUnrestricted() || permission.IsEmpty()) {
         return permission.Copy();
     }
     if (permission.IsUnrestricted() || this.IsEmpty()) {
         return this.Copy();
     }
     // if we get here, both permissions are set to 'AllowedAtrs'
     SmartcardPermission retPerm = new SmartcardPermission(SmartcardConnectOption.AllowedAtrs);
     foreach (Atr a in this.m_AllowedAtrs) {
         if (permission.m_AllowedAtrs.Contains(a))
             retPerm.m_AllowedAtrs.AddLast(a);
     }
     if (retPerm.m_AllowedAtrs.Count == 0) {
         retPerm.m_Options = SmartcardConnectOption.None;
     }
     return retPerm;
 }