summary refs log tree commit diff
path: root/crypto/src/pkix/ReasonsMask.cs
blob: e389bfe113071c87cf16230efd2cff10d0f8322d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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); }
		}
	}
}