KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > crypto > asn1 > x509 > KeyUsage


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

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

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

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