ReasonFlags.java revision f33eae7e84eb6d3b0f4e86b59605bb3de73009f3
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* @author Alexander Y. Kleymenov 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.x509; 24 25import java.io.IOException; 26 27import org.apache.harmony.security.asn1.ASN1BitString; 28import org.apache.harmony.security.asn1.BerInputStream; 29import org.apache.harmony.security.asn1.BerOutputStream; 30 31/** 32 * The class encapsulates the ASN.1 DER encoding/decoding work 33 * with the following part of X.509 CRL 34 * (as specified in RFC 3280 - 35 * Internet X.509 Public Key Infrastructure. 36 * Certificate and Certificate Revocation List (CRL) Profile. 37 * http://www.ietf.org/rfc/rfc3280.txt): 38 * 39 * <pre> 40 * ReasonFlags ::= BIT STRING { 41 * unused (0), 42 * keyCompromise (1), 43 * cACompromise (2), 44 * affiliationChanged (3), 45 * superseded (4), 46 * cessationOfOperation (5), 47 * certificateHold (6), 48 * privilegeWithdrawn (7), 49 * aACompromise (8) 50 * } 51 * </pre> 52 */ 53public class ReasonFlags { 54 55 /** 56 * The names of the reasons. 57 */ 58 static final String[] REASONS = { 59 "unused", 60 "keyCompromise", 61 "cACompromise", 62 "affiliationChanged", 63 "superseded", 64 "cessationOfOperation", 65 "certificateHold", 66 "privilegeWithdrawn", 67 "aACompromise" 68 }; 69 70 // the value of extension 71 private boolean[] flags; 72 73 /** 74 * Creates the extension object corresponding to the given flags. 75 */ 76 public ReasonFlags(boolean[] flags) { 77 this.flags = flags; 78 } 79 80 /** 81 * Places the string representation of extension value 82 * into the StringBuffer object. 83 */ 84 public void dumpValue(StringBuffer buffer, String prefix) { 85 buffer.append(prefix); 86 buffer.append("ReasonFlags [\n"); 87 for (int i=0; i<flags.length; i++) { 88 if (flags[i]) { 89 buffer.append(prefix).append(" ") 90 .append(REASONS[i]).append('\n'); 91 } 92 } 93 buffer.append(prefix); 94 buffer.append("]\n"); 95 } 96 97 /** 98 * ASN.1 Encoder/Decoder. 99 */ 100 public static final ASN1BitString ASN1 = 101 new ASN1BitString.ASN1NamedBitList(REASONS.length) { 102 public Object getDecodedObject(BerInputStream in) throws IOException { 103 return new ReasonFlags((boolean[]) super.getDecodedObject(in)); 104 } 105 106 public void setEncodingContent(BerOutputStream out) { 107 out.content = ((ReasonFlags) out.content).flags; 108 super.setEncodingContent(out); 109 } 110 }; 111} 112 113