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.
18 package java.security.cert;
20 import java.io.IOException;
21 import org.apache.harmony.security.asn1.ObjectIdentifier;
22 import org.apache.harmony.security.utils.Array;
26 * This class implements a policy qualifier as defined by the ASN.1
27 * {@code PolicyQualifierInfo} structure.
29 public class PolicyQualifierInfo {
30 // This PolicyQualifierInfo DER encoding
31 private final byte[] encoded;
32 // This PolicyQualifierInfo policy qualifier id -
33 // OID represented as String containing non-negative integers
34 // separated by periods
35 private final String policyQualifierId;
36 // DER encoding of the policy qualifier - part of encoded
37 private final byte[] policyQualifier;
40 * Creates a new {@code PolicyQualifierInfo} from the specified encoded
44 * the DER encoded policy qualifier.
46 * the policy qualifier cannot be decoded.
48 public PolicyQualifierInfo(byte[] encoded) throws IOException {
49 if (encoded == null) {
50 throw new NullPointerException("encoded == null");
52 if (encoded.length == 0) {
53 throw new IOException("encoded.length == 0");
55 this.encoded = new byte[encoded.length];
56 System.arraycopy(encoded, 0, this.encoded, 0, this.encoded.length);
59 Object[] decoded = (Object[]) org.apache.harmony.security.x509.PolicyQualifierInfo.ASN1
60 .decode(this.encoded);
61 policyQualifierId = ObjectIdentifier.toString((int[]) decoded[0]);
62 policyQualifier = (byte[]) decoded[1];
66 * Returns a ASN.1 DER encoded copy of policy qualifier info.
68 * @return a ASN.1 DER encoded copy of policy qualifier info.
70 public final byte[] getEncoded() {
71 byte[] ret = new byte[encoded.length];
72 System.arraycopy(encoded, 0, ret, 0, encoded.length);
77 * Returns the identifier (an OID) of this policy qualifier info.
79 * @return the identifier of this policy qualifier info.
81 public final String getPolicyQualifierId() {
82 return policyQualifierId;
86 * Returns a ASN.1 DER encoded copy of the qualifier of this policy
89 * @return a ASN.1 DER encoded copy of the qualifier of this policy
92 public final byte[] getPolicyQualifier() {
93 if (policyQualifier == null) {
96 byte[] ret = new byte[policyQualifier.length];
97 System.arraycopy(policyQualifier, 0, ret, 0, policyQualifier.length);
102 * Returns a string representation of this {@code PolicyQualifierInfo}
105 * @return a string representation of this {@code PolicyQualifierInfo}
108 public String toString() {
110 new StringBuilder("PolicyQualifierInfo: [\npolicyQualifierId: ");
111 sb.append(policyQualifierId);
112 sb.append("\npolicyQualifier: \n");
113 sb.append(Array.toString(policyQualifier, " "));
115 return sb.toString();