KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > KeyUsage


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 package org.apache.geronimo.util.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.DERBitString;
21
22 /**
23  * The KeyUsage object.
24  * <pre>
25  * id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 }
26  *
27  * KeyUsage ::= BIT STRING {
28  * digitalSignature (0),
29  * nonRepudiation (1),
30  * keyEncipherment (2),
31  * dataEncipherment (3),
32  * keyAgreement (4),
33  * keyCertSign (5),
34  * cRLSign (6),
35  * encipherOnly (7),
36  * decipherOnly (8) }
37  * </pre>
38  */

39 public class KeyUsage
40     extends DERBitString
41 {
42     public static final int digitalSignature = (1 << 7);
43     public static final int nonRepudiation = (1 << 6);
44     public static final int keyEncipherment = (1 << 5);
45     public static final int dataEncipherment = (1 << 4);
46     public static final int keyAgreement = (1 << 3);
47     public static final int keyCertSign = (1 << 2);
48     public static final int cRLSign = (1 << 1);
49     public static final int encipherOnly = (1 << 0);
50     public static final int decipherOnly = (1 << 15);
51
52     /**
53      * Basic constructor.
54      *
55      * @param usage - the bitwise OR of the Key Usage flags giving the
56      * allowed uses for the key.
57      * e.g. (KeyUsage.keyEncipherment | KeyUsage.dataEncipherment)
58      */

59     public KeyUsage(
60         int usage)
61     {
62         super(getBytes(usage), getPadBits(usage));
63     }
64
65     public KeyUsage(
66         DERBitString usage)
67     {
68         super(usage.getBytes(), usage.getPadBits());
69     }
70
71     public String JavaDoc toString()
72     {
73         if (data.length == 1)
74         {
75             return "KeyUsage: 0x" + Integer.toHexString(data[0] & 0xff);
76         }
77         return "KeyUsage: 0x" + Integer.toHexString((data[1] & 0xff) << 8 | (data[0] & 0xff));
78     }
79 }
80
Popular Tags