1 /* 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 8 * 9 * 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 */ 17 18 /** 19 * @author Alexander Y. Kleymenov 20 * @version $Revision$ 21 */ 22 23 package org.apache.harmony.security.x509; 24 25 import org.apache.harmony.security.asn1.ASN1Any; 26 import org.apache.harmony.security.asn1.ASN1Oid; 27 import org.apache.harmony.security.asn1.ASN1Sequence; 28 import org.apache.harmony.security.asn1.ASN1Type; 29 import org.apache.harmony.security.asn1.BerInputStream; 30 import org.apache.harmony.security.asn1.ObjectIdentifier; 31 32 /** 33 * The class encapsulates the ASN.1 DER encoding/decoding work 34 * with PolicyInformation structure which is a subpart of certificatePolicies 35 * (as specified in RFC 3280 - 36 * Internet X.509 Public Key Infrastructure. 37 * Certificate and Certificate Revocation List (CRL) Profile. 38 * http://www.ietf.org/rfc/rfc3280.txt): 39 * 40 * <pre> 41 * PolicyInformation ::= SEQUENCE { 42 * policyIdentifier CertPolicyId, 43 * policyQualifiers SEQUENCE SIZE (1..MAX) OF 44 * PolicyQualifierInfo OPTIONAL 45 * } 46 * </pre> 47 * 48 * TODO: This class is not fully implemented, implemented only work 49 * with OIDs. 50 */ 51 public final class PolicyInformation { 52 /** the value of policyIdentifier field of the structure */ 53 private final String policyIdentifier; 54 /** the ASN.1 encoded form of PolicyInformation */ 55 private byte[] encoding; 56 57 public PolicyInformation(String policyIdentifier) { 58 this.policyIdentifier = policyIdentifier; 59 } 60 61 /** 62 * Returns the value of policyIdentifier field of the structure. 63 */ 64 public String getPolicyIdentifier() { 65 return policyIdentifier; 66 } 67 68 /** 69 * Returns ASN.1 encoded form of this X.509 PolicyInformation value. 70 */ 71 public byte[] getEncoded() { 72 if (encoding == null) { 73 encoding = ASN1.encode(this); 74 } 75 return encoding; 76 } 77 78 public void dumpValue(StringBuilder sb) { 79 sb.append("Policy Identifier [").append(policyIdentifier).append(']'); 80 } 81 82 /** 83 * ASN.1 DER X.509 PolicyInformation encoder/decoder class. 84 */ 85 public static final ASN1Sequence ASN1 = new ASN1Sequence( 86 new ASN1Type[] { ASN1Oid.getInstance(), ASN1Any.getInstance() }) { 87 { 88 setOptional(1); 89 } 90 91 @Override protected Object getDecodedObject(BerInputStream in) { 92 Object[] values = (Object[]) in.content; 93 return new PolicyInformation(ObjectIdentifier.toString((int[]) values[0])); 94 } 95 96 @Override protected void getValues(Object object, Object[] values) { 97 PolicyInformation pi = (PolicyInformation) object; 98 values[0] = ObjectIdentifier.toIntArray(pi.policyIdentifier); 99 } 100 }; 101 } 102