Home | History | Annotate | Download | only in x509
      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 
     23 package org.apache.harmony.security.x509;
     24 
     25 import java.io.IOException;
     26 import org.apache.harmony.security.asn1.ASN1BitString;
     27 import org.apache.harmony.security.asn1.BerInputStream;
     28 import org.apache.harmony.security.asn1.BerOutputStream;
     29 
     30 /**
     31  * The class encapsulates the ASN.1 DER encoding/decoding work
     32  * with the following part of X.509 CRL
     33  * (as specified in RFC 3280 -
     34  *  Internet X.509 Public Key Infrastructure.
     35  *  Certificate and Certificate Revocation List (CRL) Profile.
     36  *  http://www.ietf.org/rfc/rfc3280.txt):
     37  *
     38  * <pre>
     39  *  ReasonFlags ::= BIT STRING {
     40  *        unused                  (0),
     41  *        keyCompromise           (1),
     42  *        cACompromise            (2),
     43  *        affiliationChanged      (3),
     44  *        superseded              (4),
     45  *        cessationOfOperation    (5),
     46  *        certificateHold         (6),
     47  *        privilegeWithdrawn      (7),
     48  *        aACompromise            (8)
     49  *  }
     50  *  </pre>
     51  */
     52 public final class ReasonFlags {
     53 
     54     /**
     55      * The names of the reasons.
     56      */
     57     static final String[] REASONS = {
     58         "unused",
     59         "keyCompromise",
     60         "cACompromise",
     61         "affiliationChanged",
     62         "superseded",
     63         "cessationOfOperation",
     64         "certificateHold",
     65         "privilegeWithdrawn",
     66         "aACompromise"
     67     };
     68 
     69     /** the value of extension */
     70     private final boolean[] flags;
     71 
     72     /**
     73      * Creates the extension object corresponding to the given flags.
     74      */
     75     public ReasonFlags(boolean[] flags) {
     76         this.flags = flags;
     77     }
     78 
     79     public void dumpValue(StringBuilder sb, String prefix) {
     80         sb.append(prefix);
     81         sb.append("ReasonFlags [\n");
     82         for (int i=0; i<flags.length; i++) {
     83             if (flags[i]) {
     84                 sb.append(prefix).append("  ").append(REASONS[i]).append('\n');
     85             }
     86         }
     87         sb.append(prefix);
     88         sb.append("]\n");
     89     }
     90 
     91     /**
     92      * ASN.1 Encoder/Decoder.
     93      */
     94     public static final ASN1BitString ASN1 =
     95                             new ASN1BitString.ASN1NamedBitList(REASONS.length) {
     96         public Object getDecodedObject(BerInputStream in) throws IOException {
     97             return new ReasonFlags((boolean[]) super.getDecodedObject(in));
     98         }
     99 
    100         public void setEncodingContent(BerOutputStream out) {
    101             out.content = ((ReasonFlags) out.content).flags;
    102             super.setEncodingContent(out);
    103         }
    104     };
    105 }
    106