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 */ ReasonsMask(ReasonFlags reasons)18 ReasonsMask(ReasonFlags reasons) 19 { 20 _reasons = reasons.intValue(); 21 } 22 ReasonsMask(int reasons)23 private ReasonsMask(int reasons) 24 { 25 _reasons = reasons; 26 } 27 28 /** 29 * A reason mask with no reason. 30 * 31 */ ReasonsMask()32 ReasonsMask() 33 { 34 this(0); 35 } 36 37 /** 38 * A mask with all revocation reasons. 39 */ 40 static final ReasonsMask allReasons = new ReasonsMask(ReasonFlags.aACompromise 41 | ReasonFlags.affiliationChanged | ReasonFlags.cACompromise 42 | ReasonFlags.certificateHold | ReasonFlags.cessationOfOperation 43 | ReasonFlags.keyCompromise | ReasonFlags.privilegeWithdrawn 44 | ReasonFlags.unused | ReasonFlags.superseded); 45 46 /** 47 * Adds all reasons from the reasons mask to this mask. 48 * 49 * @param mask The reasons mask to add. 50 */ addReasons(ReasonsMask mask)51 void addReasons(ReasonsMask mask) 52 { 53 _reasons = _reasons | mask.getReasons(); 54 } 55 56 /** 57 * Returns <code>true</code> if this reasons mask contains all possible 58 * reasons. 59 * 60 * @return <code>true</code> if this reasons mask contains all possible 61 * reasons. 62 */ isAllReasons()63 boolean isAllReasons() 64 { 65 return _reasons == allReasons._reasons ? true : false; 66 } 67 68 /** 69 * Intersects this mask with the given reasons mask. 70 * 71 * @param mask The mask to intersect with. 72 * @return The intersection of this and teh given mask. 73 */ intersect(ReasonsMask mask)74 ReasonsMask intersect(ReasonsMask mask) 75 { 76 ReasonsMask _mask = new ReasonsMask(); 77 _mask.addReasons(new ReasonsMask(_reasons & mask.getReasons())); 78 return _mask; 79 } 80 81 /** 82 * Returns <code>true</code> if the passed reasons mask has new reasons. 83 * 84 * @param mask The reasons mask which should be tested for new reasons. 85 * @return <code>true</code> if the passed reasons mask has new reasons. 86 */ hasNewReasons(ReasonsMask mask)87 boolean hasNewReasons(ReasonsMask mask) 88 { 89 return ((_reasons | mask.getReasons() ^ _reasons) != 0); 90 } 91 92 /** 93 * Returns the reasons in this mask. 94 * 95 * @return Returns the reasons. 96 */ getReasons()97 int getReasons() 98 { 99 return _reasons; 100 } 101 } 102