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:
022: import org.apache.harmony.security.asn1.ASN1Enumerated;
023: import org.apache.harmony.security.asn1.ASN1Type;
024:
025: /**
026: * CRL Entry's Reason Code Extension (OID = 2.5.29.21).
027: * <pre>
028: * id-ce-cRLReason OBJECT IDENTIFIER ::= { id-ce 21 }
029: *
030: * -- reasonCode ::= { CRLReason }
031: * CRLReason ::= ENUMERATED {
032: * unspecified (0),
033: * keyCompromise (1),
034: * cACompromise (2),
035: * affiliationChanged (3),
036: * superseded (4),
037: * cessationOfOperation (5),
038: * certificateHold (6),
039: * removeFromCRL (8),
040: * privilegeWithdrawn (9),
041: * aACompromise (10)
042: * }
043: * </pre>
044: * (as specified in RFC 3280 http://www.ietf.org/rfc/rfc3280.txt)
045: */
046: public class ReasonCode extends ExtensionValue {
047:
048: // predefined reason code values
049: public static final byte UNSPECIFIED = 0;
050: public static final byte KEY_COMPROMISE = 1;
051: public static final byte CA_COMPROMISE = 2;
052: public static final byte AFFILIATION_CHANGED = 3;
053: public static final byte SUPERSEDED = 4;
054: public static final byte CESSATION_OF_OPERATION = 5;
055: public static final byte CERTIFICATE_HOLD = 6;
056: public static final byte REMOVE_FROM_CRL = 8;
057: public static final byte PRIVILEGE_WITHDRAWN = 9;
058: public static final byte AA_COMPROMISE = 10;
059:
060: // the reason code value
061: private final byte code;
062:
063: public ReasonCode(byte code) {
064: this .code = code;
065: }
066:
067: public ReasonCode(byte[] encoding) throws IOException {
068: super (encoding);
069: this .code = ((byte[]) ASN1.decode(encoding))[0];
070: }
071:
072: public int getCode() {
073: return code;
074: }
075:
076: /**
077: * Returns ASN.1 encoded form of this X.509 ReasonCode value.
078: * @return a byte array containing ASN.1 encode form.
079: */
080: public byte[] getEncoded() {
081: if (encoding == null) {
082: encoding = ASN1.encode(new byte[] { (byte) code });
083: }
084: return encoding;
085: }
086:
087: /**
088: * Places the string representation of extension value
089: * into the StringBuffer object.
090: */
091: public void dumpValue(StringBuffer buffer, String prefix) {
092: buffer.append(prefix).append("Reason Code: [ "); //$NON-NLS-1$
093: switch (code) {
094: case UNSPECIFIED:
095: buffer.append("unspecified"); //$NON-NLS-1$
096: break;
097: case KEY_COMPROMISE:
098: buffer.append("keyCompromise"); //$NON-NLS-1$
099: break;
100: case CA_COMPROMISE:
101: buffer.append("cACompromise"); //$NON-NLS-1$
102: break;
103: case AFFILIATION_CHANGED:
104: buffer.append("affiliationChanged"); //$NON-NLS-1$
105: break;
106: case SUPERSEDED:
107: buffer.append("superseded"); //$NON-NLS-1$
108: break;
109: case CESSATION_OF_OPERATION:
110: buffer.append("cessationOfOperation"); //$NON-NLS-1$
111: break;
112: case CERTIFICATE_HOLD:
113: buffer.append("certificateHold"); //$NON-NLS-1$
114: break;
115: case REMOVE_FROM_CRL:
116: buffer.append("removeFromCRL"); //$NON-NLS-1$
117: break;
118: case PRIVILEGE_WITHDRAWN:
119: buffer.append("privilegeWithdrawn"); //$NON-NLS-1$
120: break;
121: case AA_COMPROMISE:
122: buffer.append("aACompromise"); //$NON-NLS-1$
123: break;
124: }
125: buffer.append(" ]\n"); //$NON-NLS-1$
126: }
127:
128: /**
129: * ASN.1 Encoder/Decoder.
130: */
131: public static final ASN1Type ASN1 = ASN1Enumerated.getInstance();
132: }
|