1    package org.bouncycastle.asn1.x509;
2    
3    import org.bouncycastle.asn1.*;
4    
5    /**
6     * <pre>
7     *    id-ce-keyUsage OBJECT IDENTIFIER ::=  { id-ce 15 }
8     *
9     *    KeyUsage ::= BIT STRING {
10    *         digitalSignature        (0),
11    *         nonRepudiation          (1),
12    *         keyEncipherment         (2),
13    *         dataEncipherment        (3),
14    *         keyAgreement            (4),
15    *         keyCertSign             (5),
16    *         cRLSign                 (6),
17    *         encipherOnly            (7),
18    *         decipherOnly            (8) }
19    * </pre>
20    */
21   public class KeyUsage
22       extends DERBitString
23   {
24       public static final int        digitalSignature = (1 << 7); 
25       public static final int        nonRepudiation   = (1 << 6);
26       public static final int        keyEncipherment  = (1 << 5);
27       public static final int        dataEncipherment = (1 << 4);
28       public static final int        keyAgreement     = (1 << 3);
29       public static final int        keyCertSign      = (1 << 2);
30       public static final int        cRLSign          = (1 << 1);
31       public static final int        encipherOnly     = (1 << 0);
32       public static final int        decipherOnly     = (1 << 15);
33   
34       /**
35        * Basic constructor.
36        * 
37        * @param usage - the bitwise OR of the Key Usage flags giving the
38        * allowed uses for the key.
39        * e.g. (X509KeyUsage.keyEncipherment | X509KeyUsage.dataEncipherment)
40        */
41       public KeyUsage(
42           int usage)
43       {
44           super(getBytes(usage), getPadBits(usage));
45       }
46   
47       public KeyUsage(
48           DERBitString usage)
49       {
50           super(usage.getBytes(), usage.getPadBits());
51       }
52   
53       public String toString()
54       {
55           return "KeyUsage: 0x" + Integer.toHexString(data[0] & 0xff);
56       }
57   }
58