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.ASN1BitString;
024: import org.apache.harmony.security.asn1.ASN1Sequence;
025: import org.apache.harmony.security.asn1.ASN1Type;
026: import org.apache.harmony.security.asn1.BerInputStream;
027: import org.apache.harmony.security.asn1.BitString;
028: import org.apache.harmony.security.utils.Array;
029:
030: /**
031: * The class encapsulates the ASN.1 DER encoding/decoding work
032: * with the X.509 CRL. Its ASN notation is as follows
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: * CertificateList ::= SEQUENCE {
040: * tbsCertList TBSCertList,
041: * signatureAlgorithm AlgorithmIdentifier,
042: * signatureValue BIT STRING
043: * }
044: * </pre>
045: */
046: public class CertificateList {
047:
048: // the value of tbsCertList field of the structure
049: private final TBSCertList tbsCertList;
050: // the value of signatureAlgorithm field of the structure
051: private final AlgorithmIdentifier signatureAlgorithm;
052: // the value of signatureValue field of the structure
053: private final byte[] signatureValue;
054: // the ASN.1 encoded form of CertList
055: private byte[] encoding;
056:
057: /**
058: * TODO
059: * @param tbsCertList: TBSCertList
060: * @param signatureAlgorithm: AlgorithmIdentifier
061: * @param signatureValue: byte[]
062: */
063: public CertificateList(TBSCertList tbsCertList,
064: AlgorithmIdentifier signatureAlgorithm,
065: byte[] signatureValue) {
066: this .tbsCertList = tbsCertList;
067: this .signatureAlgorithm = signatureAlgorithm;
068: this .signatureValue = new byte[signatureValue.length];
069: System.arraycopy(signatureValue, 0, this .signatureValue, 0,
070: signatureValue.length);
071: }
072:
073: //
074: // TODO
075: // @param tbsCertList: TBSCertList
076: // @param signatureAlgorithm: AlgorithmIdentifier
077: // @param signatureValue: byte[]
078: // @param encoding: byte[]
079: //
080: private CertificateList(TBSCertList tbsCertList,
081: AlgorithmIdentifier signatureAlgorithm,
082: byte[] signatureValue, byte[] encoding) {
083: this (tbsCertList, signatureAlgorithm, signatureValue);
084: this .encoding = encoding;
085: }
086:
087: /**
088: * Returns the value of tbsCertList field of the structure.
089: * @return tbsCertList
090: */
091: public TBSCertList getTbsCertList() {
092: return tbsCertList;
093: }
094:
095: /**
096: * Returns the value of signatureAlgorithm field of the structure.
097: * @return signatureAlgorithm
098: */
099: public AlgorithmIdentifier getSignatureAlgorithm() {
100: return signatureAlgorithm;
101: }
102:
103: /**
104: * Returns the value of signatureValue field of the structure.
105: * @return signatureValue
106: */
107: public byte[] getSignatureValue() {
108: byte[] result = new byte[signatureValue.length];
109: System.arraycopy(signatureValue, 0, result, 0,
110: signatureValue.length);
111: return result;
112: }
113:
114: public String toString() {
115: StringBuffer res = new StringBuffer();
116: tbsCertList.dumpValue(res);
117: res.append("\nSignature Value:\n"); //$NON-NLS-1$
118: res.append(Array.toString(signatureValue, "")); //$NON-NLS-1$
119: return res.toString();
120: }
121:
122: /**
123: * Returns ASN.1 encoded form of this X.509 TBSCertList value.
124: * @return a byte array containing ASN.1 encode form.
125: */
126: public byte[] getEncoded() {
127: if (encoding == null) {
128: encoding = CertificateList.ASN1.encode(this );
129: }
130: return encoding;
131: }
132:
133: /**
134: * X.509 CertList encoder/decoder.
135: */
136: public static final ASN1Sequence ASN1 = new ASN1Sequence(
137: new ASN1Type[] { TBSCertList.ASN1,
138: AlgorithmIdentifier.ASN1,
139: ASN1BitString.getInstance() }) {
140:
141: protected Object getDecodedObject(BerInputStream in) {
142: Object[] values = (Object[]) in.content;
143: return new CertificateList((TBSCertList) values[0],
144: (AlgorithmIdentifier) values[1],
145: ((BitString) values[2]).bytes, // FIXME keep as BitString object
146: in.getEncoded());
147: }
148:
149: protected void getValues(Object object, Object[] values) {
150:
151: CertificateList certlist = (CertificateList) object;
152:
153: values[0] = certlist.tbsCertList;
154: values[1] = certlist.signatureAlgorithm;
155: values[2] = new BitString(certlist.signatureValue, 0);
156: }
157: };
158: }
|