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: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.security.x509;
022:
023: import org.apache.harmony.security.asn1.ASN1Any;
024: import org.apache.harmony.security.asn1.ASN1Oid;
025: import org.apache.harmony.security.asn1.ASN1Sequence;
026: import org.apache.harmony.security.asn1.ASN1Type;
027: import org.apache.harmony.security.asn1.BerInputStream;
028: import org.apache.harmony.security.asn1.ObjectIdentifier;
029:
030: /**
031: * The class encapsulates the ASN.1 DER encoding/decoding work
032: * with PolicyInformation structure which is a subpart of certificatePolicies
033: * (as specified in RFC 3280 -
034: * Internet X.509 Public Key Infrastructure.
035: * Certificate and Certificate Revocation List (CRL) Profile.
036: * http://www.ietf.org/rfc/rfc3280.txt):
037: *
038: * <pre>
039: * PolicyInformation ::= SEQUENCE {
040: * policyIdentifier CertPolicyId,
041: * policyQualifiers SEQUENCE SIZE (1..MAX) OF
042: * PolicyQualifierInfo OPTIONAL
043: * }
044: * </pre>
045: *
046: * TODO: This class is not fully implemented, implemented only work
047: * with OIDs.
048: */
049:
050: public class PolicyInformation {
051:
052: // the value of policyIdentifier field of the structure
053: private String policyIdentifier;
054: // the ASN.1 encoded form of PolicyInformation
055: private byte[] encoding;
056:
057: /**
058: * TODO
059: * @param policyIdentifier: String
060: */
061: public PolicyInformation(String policyIdentifier) {
062: this .policyIdentifier = policyIdentifier;
063: }
064:
065: /**
066: * Returns the value of policyIdentifier field of the structure.
067: * @return policyIdentifier
068: */
069: public String getPolicyIdentifier() {
070: return policyIdentifier;
071: }
072:
073: /**
074: * Returns ASN.1 encoded form of this X.509 PolicyInformation value.
075: * @return a byte array containing ASN.1 encode form.
076: */
077: public byte[] getEncoded() {
078: if (encoding == null) {
079: encoding = ASN1.encode(this );
080: }
081: return encoding;
082: }
083:
084: /**
085: * Places the string representation of extension value
086: * into the StringBuffer object.
087: */
088: public void dumpValue(StringBuffer buffer) {
089: buffer.append("Policy Identifier [") //$NON-NLS-1$
090: .append(policyIdentifier).append(']');
091: }
092:
093: /**
094: * ASN.1 DER X.509 PolicyInformation encoder/decoder class.
095: */
096: public static final ASN1Sequence ASN1 = new ASN1Sequence(
097: new ASN1Type[] { ASN1Oid.getInstance(),
098: ASN1Any.getInstance() }) {
099: {
100: setOptional(1);
101: }
102:
103: protected Object getDecodedObject(BerInputStream in) {
104: Object[] values = (Object[]) in.content;
105: return new PolicyInformation(ObjectIdentifier
106: .toString((int[]) values[0]));
107: }
108:
109: protected void getValues(Object object, Object[] values) {
110:
111: PolicyInformation pi = (PolicyInformation) object;
112:
113: values[0] = ObjectIdentifier
114: .toIntArray(pi.policyIdentifier);
115: }
116: };
117: }
|