using System;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Pkix
{
///
/// This class helps to handle CRL revocation reasons mask. Each CRL handles a
/// certain set of revocation reasons.
///
internal class ReasonsMask
{
private int _reasons;
///
/// Constructs are reason mask with the reasons.
///
/// The reasons.
internal ReasonsMask(
int reasons)
{
_reasons = reasons;
}
///
/// A reason mask with no reason.
///
internal ReasonsMask()
: this(0)
{
}
///
/// A mask with all revocation reasons.
///
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;
}
///
/// Returns true
if this reasons mask contains all possible
/// reasons.
///
/// true if this reasons mask contains all possible reasons.
///
internal bool IsAllReasons
{
get { return _reasons == AllReasons._reasons; }
}
///
/// Intersects this mask with the given reasons mask.
///
/// mask The mask to intersect with.
/// The intersection of this and teh given mask.
internal ReasonsMask Intersect(
ReasonsMask mask)
{
ReasonsMask _mask = new ReasonsMask();
_mask.AddReasons(new ReasonsMask(_reasons & mask.Reasons.IntValue));
return _mask;
}
///
/// Returns true if the passed reasons mask has new reasons.
///
/// The reasons mask which should be tested for new reasons.
/// true if the passed reasons mask has new reasons.
internal bool HasNewReasons(
ReasonsMask mask)
{
return ((_reasons | mask.Reasons.IntValue ^ _reasons) != 0);
}
///
/// Returns the reasons in this mask.
///
public ReasonFlags Reasons
{
get { return new ReasonFlags(_reasons); }
}
}
}