/// <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); }
/// <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); }
/// <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); }
/// <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; }