1 package org.bouncycastle.asn1.x509; 2 3 import org.bouncycastle.asn1.ASN1Encodable; 4 import org.bouncycastle.asn1.ASN1EncodableVector; 5 import org.bouncycastle.asn1.ASN1Object; 6 import org.bouncycastle.asn1.ASN1ObjectIdentifier; 7 import org.bouncycastle.asn1.ASN1Primitive; 8 import org.bouncycastle.asn1.ASN1Sequence; 9 import org.bouncycastle.asn1.DERIA5String; 10 import org.bouncycastle.asn1.DERSequence; 11 12 /** 13 * Policy qualifiers, used in the X509V3 CertificatePolicies 14 * extension. 15 * 16 * <pre> 17 * PolicyQualifierInfo ::= SEQUENCE { 18 * policyQualifierId PolicyQualifierId, 19 * qualifier ANY DEFINED BY policyQualifierId } 20 * 21 * PolicyQualifierId ::= OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice ) 22 * </pre> 23 */ 24 public class PolicyQualifierInfo 25 extends ASN1Object 26 { 27 private ASN1ObjectIdentifier policyQualifierId; 28 private ASN1Encodable qualifier; 29 30 /** 31 * Creates a new <code>PolicyQualifierInfo</code> instance. 32 * 33 * @param policyQualifierId a <code>PolicyQualifierId</code> value 34 * @param qualifier the qualifier, defined by the above field. 35 */ PolicyQualifierInfo( ASN1ObjectIdentifier policyQualifierId, ASN1Encodable qualifier)36 public PolicyQualifierInfo( 37 ASN1ObjectIdentifier policyQualifierId, 38 ASN1Encodable qualifier) 39 { 40 this.policyQualifierId = policyQualifierId; 41 this.qualifier = qualifier; 42 } 43 44 /** 45 * Creates a new <code>PolicyQualifierInfo</code> containing a 46 * cPSuri qualifier. 47 * 48 * @param cps the CPS (certification practice statement) uri as a 49 * <code>String</code>. 50 */ PolicyQualifierInfo( String cps)51 public PolicyQualifierInfo( 52 String cps) 53 { 54 policyQualifierId = PolicyQualifierId.id_qt_cps; 55 qualifier = new DERIA5String (cps); 56 } 57 58 /** 59 * Creates a new <code>PolicyQualifierInfo</code> instance. 60 * 61 * @param as <code>PolicyQualifierInfo</code> X509 structure 62 * encoded as an ASN1Sequence. 63 * @deprecated use PolicyQualifierInfo.getInstance() 64 */ PolicyQualifierInfo( ASN1Sequence as)65 public PolicyQualifierInfo( 66 ASN1Sequence as) 67 { 68 if (as.size() != 2) 69 { 70 throw new IllegalArgumentException("Bad sequence size: " 71 + as.size()); 72 } 73 74 policyQualifierId = ASN1ObjectIdentifier.getInstance(as.getObjectAt(0)); 75 qualifier = as.getObjectAt(1); 76 } 77 getInstance( Object obj)78 public static PolicyQualifierInfo getInstance( 79 Object obj) 80 { 81 if (obj instanceof PolicyQualifierInfo) 82 { 83 return (PolicyQualifierInfo)obj; 84 } 85 else if (obj != null) 86 { 87 return new PolicyQualifierInfo(ASN1Sequence.getInstance(obj)); 88 } 89 90 return null; 91 } 92 93 getPolicyQualifierId()94 public ASN1ObjectIdentifier getPolicyQualifierId() 95 { 96 return policyQualifierId; 97 } 98 getQualifier()99 public ASN1Encodable getQualifier() 100 { 101 return qualifier; 102 } 103 104 /** 105 * Returns a DER-encodable representation of this instance. 106 * 107 * @return a <code>ASN1Primitive</code> value 108 */ toASN1Primitive()109 public ASN1Primitive toASN1Primitive() 110 { 111 ASN1EncodableVector dev = new ASN1EncodableVector(); 112 dev.add(policyQualifierId); 113 dev.add(qualifier); 114 115 return new DERSequence(dev); 116 } 117 } 118