001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.crypto.asn1.x509;
017:
018: import java.util.Enumeration;
019: import java.util.Vector;
020:
021: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
022: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
023: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
024: import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
025: import org.apache.geronimo.crypto.asn1.DERObject;
026: import org.apache.geronimo.crypto.asn1.DERObjectIdentifier;
027: import org.apache.geronimo.crypto.asn1.DERSequence;
028:
029: public class CertificatePolicies extends ASN1Encodable {
030: static final DERObjectIdentifier anyPolicy = new DERObjectIdentifier(
031: "2.5.29.32.0");
032:
033: Vector policies = new Vector();
034:
035: /**
036: * @deprecated use an ASN1Sequence of PolicyInformation
037: */
038: public static CertificatePolicies getInstance(ASN1TaggedObject obj,
039: boolean explicit) {
040: return getInstance(ASN1Sequence.getInstance(obj, explicit));
041: }
042:
043: /**
044: * @deprecated use an ASN1Sequence of PolicyInformation
045: */
046: public static CertificatePolicies getInstance(Object obj) {
047: if (obj instanceof CertificatePolicies) {
048: return (CertificatePolicies) obj;
049: } else if (obj instanceof ASN1Sequence) {
050: return new CertificatePolicies((ASN1Sequence) obj);
051: }
052:
053: throw new IllegalArgumentException("unknown object in factory");
054: }
055:
056: /**
057: * @deprecated use an ASN1Sequence of PolicyInformation
058: */
059: public CertificatePolicies(ASN1Sequence seq) {
060: Enumeration e = seq.getObjects();
061: while (e.hasMoreElements()) {
062: ASN1Sequence s = (ASN1Sequence) e.nextElement();
063: policies.addElement(s.getObjectAt(0));
064: }
065: // For now we just don't handle PolicyQualifiers
066: }
067:
068: /**
069: * create a certificate policy with the given OID.
070: * @deprecated use an ASN1Sequence of PolicyInformation
071: */
072: public CertificatePolicies(DERObjectIdentifier p) {
073: policies.addElement(p);
074: }
075:
076: /**
077: * create a certificate policy with the policy given by the OID represented
078: * by the string p.
079: * @deprecated use an ASN1Sequence of PolicyInformation
080: */
081: public CertificatePolicies(String p) {
082: this (new DERObjectIdentifier(p));
083: }
084:
085: public void addPolicy(String p) {
086: policies.addElement(new DERObjectIdentifier(p));
087: }
088:
089: public String getPolicy(int nr) {
090: if (policies.size() > nr)
091: return ((DERObjectIdentifier) policies.elementAt(nr))
092: .getId();
093:
094: return null;
095: }
096:
097: /**
098: * <pre>
099: * certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
100: *
101: * PolicyInformation ::= SEQUENCE {
102: * policyIdentifier CertPolicyId,
103: * policyQualifiers SEQUENCE SIZE (1..MAX) OF
104: * PolicyQualifierInfo OPTIONAL }
105: *
106: * CertPolicyId ::= OBJECT IDENTIFIER
107: *
108: * PolicyQualifierInfo ::= SEQUENCE {
109: * policyQualifierId PolicyQualifierId,
110: * qualifier ANY DEFINED BY policyQualifierId }
111: *
112: * PolicyQualifierId ::=
113: * OBJECT IDENTIFIER ( id-qt-cps | id-qt-unotice )
114: * </pre>
115: * @deprecated use an ASN1Sequence of PolicyInformation
116: */
117: public DERObject toASN1Object() {
118: ASN1EncodableVector v = new ASN1EncodableVector();
119:
120: // We only do policyIdentifier yet...
121: for (int i = 0; i < policies.size(); i++) {
122: v.add(new DERSequence((DERObjectIdentifier) policies
123: .elementAt(i)));
124: }
125:
126: return new DERSequence(v);
127: }
128:
129: public String toString() {
130: String p = null;
131: for (int i = 0; i < policies.size(); i++) {
132: if (p != null)
133: p += ", ";
134: p += ((DERObjectIdentifier) policies.elementAt(i)).getId();
135: }
136: return "CertificatePolicies: " + p;
137: }
138: }
|