2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @author Alexander Y. Kleymenov
23 package org.apache.harmony.security.x509;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Iterator;
29 import java.util.List;
30 import org.apache.harmony.security.asn1.ASN1SequenceOf;
31 import org.apache.harmony.security.asn1.ASN1Type;
32 import org.apache.harmony.security.asn1.BerInputStream;
35 * The class encapsulates the ASN.1 DER encoding/decoding work
36 * with Certificate Policies structure which is a part of X.509 certificate
37 * (as specified in RFC 3280 -
38 * Internet X.509 Public Key Infrastructure.
39 * Certificate and Certificate Revocation List (CRL) Profile.
40 * http://www.ietf.org/rfc/rfc3280.txt):
43 * certificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation
48 public class CertificatePolicies extends ExtensionValue {
50 // the values of policyInformation field of the structure
51 private List policyInformations;
52 // the ASN.1 encoded form of CertificatePolicies
53 private byte[] encoding;
56 * Constructs an object representing the value of CertificatePolicies.
58 public CertificatePolicies() {}
62 * @param policyInformations: List
64 public CertificatePolicies(List policyInformations) {
65 this.policyInformations = policyInformations;
68 public static CertificatePolicies decode(byte[] encoding)
70 CertificatePolicies cps = ((CertificatePolicies) ASN1.decode(encoding));
71 cps.encoding = encoding;
77 // @param policyInformations: List
78 // @param encoding: byte[]
80 private CertificatePolicies(List policyInformations, byte[] encoding) {
81 this.policyInformations = policyInformations;
82 this.encoding = encoding;
86 * Returns the values of policyInformation field of the structure.
87 * @return policyInformations
89 public List getPolicyInformations() {
90 return new ArrayList(policyInformations);
95 * @param policyInformation: PolicyInformation
98 public CertificatePolicies addPolicyInformation(
99 PolicyInformation policyInformation) {
101 if (policyInformations == null) {
102 policyInformations = new ArrayList();
104 policyInformations.add(policyInformation);
109 * Returns ASN.1 encoded form of this X.509 CertificatePolicies value.
110 * @return a byte array containing ASN.1 encode form.
112 public byte[] getEncoded() {
113 if (encoding == null) {
114 encoding = ASN1.encode(this);
120 * Places the string representation of extension value
121 * into the StringBuffer object.
123 public void dumpValue(StringBuffer buffer, String prefix) {
124 buffer.append(prefix).append("CertificatePolicies [\n");
125 for (Iterator it=policyInformations.iterator(); it.hasNext();) {
126 buffer.append(prefix);
128 ((PolicyInformation) it.next()).dumpValue(buffer);
131 buffer.append(prefix).append("]\n");
135 * ASN.1 DER X.509 CertificatePolicies encoder/decoder class.
137 public static final ASN1Type ASN1 =
138 new ASN1SequenceOf(PolicyInformation.ASN1) {
140 public Object getDecodedObject(BerInputStream in) {
141 return new CertificatePolicies((List) in.content, in.getEncoded());
144 public Collection getValues(Object object) {
145 CertificatePolicies cps = (CertificatePolicies) object;
146 return cps.policyInformations;