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 java.io.IOException;
024:
025: import org.apache.harmony.security.asn1.ASN1BitString;
026: import org.apache.harmony.security.asn1.BerInputStream;
027: import org.apache.harmony.security.asn1.BerOutputStream;
028:
029: /**
030: * The class encapsulates the ASN.1 DER encoding/decoding work
031: * with the following part of X.509 CRL
032: * (as specified in RFC 3280 -
033: * Internet X.509 Public Key Infrastructure.
034: * Certificate and Certificate Revocation List (CRL) Profile.
035: * http://www.ietf.org/rfc/rfc3280.txt):
036: *
037: * <pre>
038: * ReasonFlags ::= BIT STRING {
039: * unused (0),
040: * keyCompromise (1),
041: * cACompromise (2),
042: * affiliationChanged (3),
043: * superseded (4),
044: * cessationOfOperation (5),
045: * certificateHold (6),
046: * privilegeWithdrawn (7),
047: * aACompromise (8)
048: * }
049: * </pre>
050: */
051: public class ReasonFlags {
052:
053: /**
054: * The names of the reasons.
055: */
056: static final String[] REASONS = { "unused", //$NON-NLS-1$
057: "keyCompromise", //$NON-NLS-1$
058: "cACompromise", //$NON-NLS-1$
059: "affiliationChanged", //$NON-NLS-1$
060: "superseded", //$NON-NLS-1$
061: "cessationOfOperation", //$NON-NLS-1$
062: "certificateHold", //$NON-NLS-1$
063: "privilegeWithdrawn", //$NON-NLS-1$
064: "aACompromise" //$NON-NLS-1$
065: };
066:
067: // the value of extension
068: private boolean[] flags;
069:
070: /**
071: * Creates the extension object corresponding to the given flags.
072: */
073: public ReasonFlags(boolean[] flags) {
074: this .flags = flags;
075: }
076:
077: /**
078: * Places the string representation of extension value
079: * into the StringBuffer object.
080: */
081: public void dumpValue(StringBuffer buffer, String prefix) {
082: buffer.append(prefix);
083: buffer.append("ReasonFlags [\n"); //$NON-NLS-1$
084: for (int i = 0; i < flags.length; i++) {
085: if (flags[i]) {
086: buffer.append(prefix).append(" ") //$NON-NLS-1$
087: .append(REASONS[i]).append('\n');
088: }
089: }
090: buffer.append(prefix);
091: buffer.append("]\n"); //$NON-NLS-1$
092: }
093:
094: /**
095: * ASN.1 Encoder/Decoder.
096: */
097: public static final ASN1BitString ASN1 = new ASN1BitString.ASN1NamedBitList(
098: REASONS.length) {
099: public Object getDecodedObject(BerInputStream in)
100: throws IOException {
101: return new ReasonFlags((boolean[]) super
102: .getDecodedObject(in));
103: }
104:
105: public void setEncodingContent(BerOutputStream out) {
106: out.content = ((ReasonFlags) out.content).flags;
107: super.setEncodingContent(out);
108: }
109: };
110: }
|