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