01: package org.bouncycastle.jce.provider;
02:
03: import org.bouncycastle.asn1.x509.ReasonFlags;
04:
05: /**
06: * This class helps to handle CRL revocation reasons mask. Each CRL handles a
07: * certain set of revocation reasons.
08: */
09: class ReasonsMask {
10: private int _reasons;
11:
12: /**
13: * Constructs are reason mask with the reasons.
14: *
15: * @param reasons The reasons.
16: */
17: ReasonsMask(int reasons) {
18: _reasons = reasons;
19: }
20:
21: /**
22: * A reason mask with no reason.
23: *
24: */
25: ReasonsMask() {
26: this (0);
27: }
28:
29: /**
30: * A mask with all revocation reasons.
31: */
32: static final ReasonsMask allReasons = new ReasonsMask(
33: ReasonFlags.aACompromise | ReasonFlags.affiliationChanged
34: | ReasonFlags.cACompromise
35: | ReasonFlags.certificateHold
36: | ReasonFlags.cessationOfOperation
37: | ReasonFlags.keyCompromise
38: | ReasonFlags.privilegeWithdrawn
39: | ReasonFlags.unused | ReasonFlags.super seded);
40:
41: /**
42: * Adds all reasons from the reasons mask to this mask.
43: *
44: * @param mask The reasons mask to add.
45: */
46: void addReasons(ReasonsMask mask) {
47: _reasons = _reasons | mask.getReasons();
48: }
49:
50: /**
51: * Returns <code>true</code> if this reasons mask contains all possible
52: * reasons.
53: *
54: * @return <code>true</code> if this reasons mask contains all possible
55: * reasons.
56: */
57: boolean isAllReasons() {
58: return _reasons == allReasons._reasons ? true : false;
59: }
60:
61: /**
62: * Intersects this mask with the given reasons mask.
63: *
64: * @param mask The mask to intersect with.
65: * @return The intersection of this and teh given mask.
66: */
67: ReasonsMask intersect(ReasonsMask mask) {
68: ReasonsMask _mask = new ReasonsMask();
69: _mask.addReasons(new ReasonsMask(_reasons & mask.getReasons()));
70: return _mask;
71: }
72:
73: /**
74: * Returns <code>true</code> if the passed reasons mask has new reasons.
75: *
76: * @param mask The reasons mask which should be tested for new reasons.
77: * @return <code>true</code> if the passed reasons mask has new reasons.
78: */
79: boolean hasNewReasons(ReasonsMask mask) {
80: return ((_reasons | mask.getReasons() ^ _reasons) != 0);
81: }
82:
83: /**
84: * Returns the reasons in this mask.
85: *
86: * @return Returns the reasons.
87: */
88: int getReasons() {
89: return _reasons;
90: }
91: }
|