diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2013-06-28 15:26:06 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2013-06-28 15:26:06 +0700 |
commit | 44288db4414158ac9b98a507b15e81d0d3c66ca6 (patch) | |
tree | aa5ef88948ebb68ed6c8df81eb5da889641a9b50 /crypto/src/pkix/ReasonsMask.cs | |
parent | Set up text/binary handling for existing file types (diff) | |
download | BouncyCastle.NET-ed25519-44288db4414158ac9b98a507b15e81d0d3c66ca6.tar.xz |
Initial import of old CVS repository
Diffstat (limited to 'crypto/src/pkix/ReasonsMask.cs')
-rw-r--r-- | crypto/src/pkix/ReasonsMask.cs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/crypto/src/pkix/ReasonsMask.cs b/crypto/src/pkix/ReasonsMask.cs new file mode 100644 index 000000000..e389bfe11 --- /dev/null +++ b/crypto/src/pkix/ReasonsMask.cs @@ -0,0 +1,96 @@ +using System; + +using Org.BouncyCastle.Asn1.X509; + +namespace Org.BouncyCastle.Pkix +{ + /// <summary> + /// This class helps to handle CRL revocation reasons mask. Each CRL handles a + /// certain set of revocation reasons. + /// </summary> + internal class ReasonsMask + { + private int _reasons; + + /// <summary> + /// Constructs are reason mask with the reasons. + /// </summary> + /// <param name="reasons">The reasons.</param> + internal ReasonsMask( + int reasons) + { + _reasons = reasons; + } + + /// <summary> + /// A reason mask with no reason. + /// </summary> + internal ReasonsMask() + : this(0) + { + } + + /// <summary> + /// A mask with all revocation reasons. + /// </summary> + internal static readonly ReasonsMask AllReasons = new ReasonsMask( + ReasonFlags.AACompromise | ReasonFlags.AffiliationChanged | ReasonFlags.CACompromise + | ReasonFlags.CertificateHold | ReasonFlags.CessationOfOperation + | ReasonFlags.KeyCompromise | ReasonFlags.PrivilegeWithdrawn | ReasonFlags.Unused + | ReasonFlags.Superseded); + + /** + * Adds all reasons from the reasons mask to this mask. + * + * @param mask The reasons mask to add. + */ + internal void AddReasons( + ReasonsMask mask) + { + _reasons = _reasons | mask.Reasons.IntValue; + } + + /// <summary> + /// Returns <code>true</code> if this reasons mask contains all possible + /// reasons. + /// </summary> + /// <returns>true if this reasons mask contains all possible reasons. + /// </returns> + internal bool IsAllReasons + { + get { return _reasons == AllReasons._reasons; } + } + + /// <summary> + /// Intersects this mask with the given reasons mask. + /// </summary> + /// <param name="mask">mask The mask to intersect with.</param> + /// <returns>The intersection of this and teh given mask.</returns> + internal ReasonsMask Intersect( + ReasonsMask mask) + { + ReasonsMask _mask = new ReasonsMask(); + _mask.AddReasons(new ReasonsMask(_reasons & mask.Reasons.IntValue)); + return _mask; + } + + /// <summary> + /// Returns <c>true</c> if the passed reasons mask has new reasons. + /// </summary> + /// <param name="mask">The reasons mask which should be tested for new reasons.</param> + /// <returns><c>true</c> if the passed reasons mask has new reasons.</returns> + internal bool HasNewReasons( + ReasonsMask mask) + { + return ((_reasons | mask.Reasons.IntValue ^ _reasons) != 0); + } + + /// <summary> + /// Returns the reasons in this mask. + /// </summary> + public ReasonFlags Reasons + { + get { return new ReasonFlags(_reasons); } + } + } +} |