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: package org.apache.harmony.security.x509;
019:
020: import java.io.IOException;
021: import javax.security.auth.x500.X500Principal;
022: import org.apache.harmony.security.asn1.ASN1Type;
023: import org.apache.harmony.security.asn1.ASN1Sequence;
024: import org.apache.harmony.security.asn1.BerInputStream;
025: import org.apache.harmony.security.x501.Name;
026:
027: /**
028: * CRL Entry's Certificate Issuer Extension (OID = 2.5.29.29).
029: * It is a CRL entry extension and contains the GeneralNames describing
030: * the issuer of revoked certificate. Its ASN.1 notation is as follows:
031: * <pre>
032: * id-ce-certificateIssuer OBJECT IDENTIFIER ::= { id-ce 29 }
033: *
034: * certificateIssuer ::= GeneralNames
035: * </pre>
036: * (as specified in RFC 3280)
037: * In java implementation it is presumed that GeneralNames consist of
038: * one element and its type is directoryName.
039: */
040: public class CertificateIssuer extends ExtensionValue {
041:
042: // certificate issuer value
043: private X500Principal issuer;
044:
045: /**
046: * Creates an object on the base of GeneralName structure.
047: */
048: public CertificateIssuer(GeneralName issuer) {
049: super (ASN1.encode(issuer));
050: }
051:
052: /**
053: * Creates an object on the base of its encoded form.
054: */
055: public CertificateIssuer(byte[] encoding) {
056: super (encoding);
057: }
058:
059: /**
060: * Returns the issuer.
061: */
062: public X500Principal getIssuer() throws IOException {
063: if (issuer == null) {
064: issuer = (X500Principal) ASN1.decode(getEncoded());
065: }
066: return issuer;
067: }
068:
069: /**
070: * Places the string representation of extension value
071: * into the StringBuffer object.
072: */
073: public void dumpValue(StringBuffer buffer, String prefix) {
074: buffer.append(prefix).append("Certificate Issuer: "); //$NON-NLS-1$
075: if (issuer == null) {
076: try {
077: issuer = getIssuer();
078: } catch (IOException e) {
079: // incorrect extension value encoding
080: buffer
081: .append("Unparseable (incorrect!) extension value:\n"); //$NON-NLS-1$
082: super .dumpValue(buffer);
083: }
084: }
085: buffer.append(issuer).append('\n');
086: }
087:
088: /**
089: * ASN.1 Encoder/Decoder.
090: */
091: public static final ASN1Type ASN1 = new ASN1Sequence(
092: new ASN1Type[] { GeneralName.ASN1 }) {
093: public Object getDecodedObject(BerInputStream in) {
094: return ((Name) ((GeneralName) ((Object[]) in.content)[0])
095: .getName()).getX500Principal();
096: }
097:
098: protected void getValues(Object object, Object[] values) {
099: values[0] = object;
100: }
101: };
102: }
|