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 23package org.apache.harmony.security.x509; 24 25import org.apache.harmony.security.asn1.ASN1Any; 26import org.apache.harmony.security.asn1.ASN1Oid; 27import org.apache.harmony.security.asn1.ASN1Sequence; 28import org.apache.harmony.security.asn1.ASN1Type; 29import org.apache.harmony.security.asn1.BerInputStream; 30import 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 52public class PolicyInformation { 53 54 // the value of policyIdentifier field of the structure 55 private String policyIdentifier; 56 // the ASN.1 encoded form of PolicyInformation 57 private byte[] encoding; 58 59 /** 60 * TODO 61 * @param policyIdentifier: String 62 */ 63 public PolicyInformation(String policyIdentifier) { 64 this.policyIdentifier = policyIdentifier; 65 } 66 67 /** 68 * Returns the value of policyIdentifier field of the structure. 69 * @return policyIdentifier 70 */ 71 public String getPolicyIdentifier() { 72 return policyIdentifier; 73 } 74 75 /** 76 * Returns ASN.1 encoded form of this X.509 PolicyInformation value. 77 * @return a byte array containing ASN.1 encode form. 78 */ 79 public byte[] getEncoded() { 80 if (encoding == null) { 81 encoding = ASN1.encode(this); 82 } 83 return encoding; 84 } 85 86 /** 87 * Places the string representation of extension value 88 * into the StringBuffer object. 89 */ 90 public void dumpValue(StringBuffer buffer) { 91 buffer.append("Policy Identifier [") //$NON-NLS-1$ 92 .append(policyIdentifier).append(']'); 93 } 94 95 /** 96 * ASN.1 DER X.509 PolicyInformation encoder/decoder class. 97 */ 98 public static final ASN1Sequence ASN1 = new ASN1Sequence( 99 new ASN1Type[] { ASN1Oid.getInstance(), ASN1Any.getInstance() }) { 100 { 101 setOptional(1); 102 } 103 104 protected Object getDecodedObject(BerInputStream in) { 105 Object[] values = (Object[]) in.content; 106 return new PolicyInformation(ObjectIdentifier 107 .toString((int[]) values[0])); 108 } 109 110 protected void getValues(Object object, Object[] values) { 111 112 PolicyInformation pi = (PolicyInformation) object; 113 114 values[0] = ObjectIdentifier.toIntArray(pi.policyIdentifier); 115 } 116 }; 117} 118 119