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