1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import org.apache.geronimo.util.asn1.ASN1Encodable;
22 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23 import org.apache.geronimo.util.asn1.ASN1Sequence;
24 import org.apache.geronimo.util.asn1.DEREncodable;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.DERIA5String;
27 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
28 import org.apache.geronimo.util.asn1.DERSequence;
29
30 /**
31 * Policy qualifiers, used in the X509V3 CertificatePolicies
32 * extension.
33 *
34 * <pre>
35 * PolicyQualifierInfo ::= SEQUENCE {
36 * policyQualifierId PolicyQualifierId,
37 * qualifier ANY DEFINED BY policyQualifierId }
38 * </pre>
39 */
40 public class PolicyQualifierInfo
41 extends ASN1Encodable
42 {
43 DERObjectIdentifier policyQualifierId;
44 DEREncodable qualifier;
45
46 /**
47 * Creates a new <code>PolicyQualifierInfo</code> instance.
48 *
49 * @param policyQualifierId a <code>PolicyQualifierId</code> value
50 * @param qualifier the qualifier, defined by the above field.
51 */
52 public PolicyQualifierInfo (DERObjectIdentifier policyQualifierId,
53 DEREncodable qualifier)
54 {
55 this.policyQualifierId = policyQualifierId;
56 this.qualifier = qualifier;
57 }
58
59 /**
60 * Creates a new <code>PolicyQualifierInfo</code> containing a
61 * cPSuri qualifier.
62 *
63 * @param cps the CPS (certification practice statement) uri as a
64 * <code>String</code>.
65 */
66 public PolicyQualifierInfo (String cps)
67 {
68 policyQualifierId = PolicyQualifierId.id_qt_cps;
69 qualifier = new DERIA5String (cps);
70 }
71
72 /**
73 * Creates a new <code>PolicyQualifierInfo</code> instance.
74 *
75 * @param as <code>PolicyQualifierInfo</code> X509 structure
76 * encoded as an ASN1Sequence.
77 */
78 public PolicyQualifierInfo (ASN1Sequence as)
79 {
80 policyQualifierId = (DERObjectIdentifier) as.getObjectAt(0);
81 qualifier = as.getObjectAt(1);
82 }
83
84 public static PolicyQualifierInfo getInstance (Object as)
85 {
86 if (as instanceof PolicyQualifierInfo)
87 {
88 return (PolicyQualifierInfo)as;
89 }
90 else if (as instanceof ASN1Sequence)
91 {
92 return new PolicyQualifierInfo((ASN1Sequence)as);
93 }
94
95 throw new IllegalArgumentException("unknown object in getInstance.");
96 }
97
98 /**
99 * Returns a DER-encodable representation of this instance.
100 *
101 * @return a <code>DERObject</code> value
102 */
103 public DERObject toASN1Object()
104 {
105 ASN1EncodableVector dev = new ASN1EncodableVector();
106 dev.add(policyQualifierId);
107 dev.add(qualifier);
108
109 return new DERSequence(dev);
110 }
111 }