01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.crypto.asn1.x509;
17:
18: import org.apache.geronimo.crypto.asn1.DERBitString;
19:
20: /**
21: * The KeyUsage object.
22: * <pre>
23: * id-ce-keyUsage OBJECT IDENTIFIER ::= { id-ce 15 }
24: *
25: * KeyUsage ::= BIT STRING {
26: * digitalSignature (0),
27: * nonRepudiation (1),
28: * keyEncipherment (2),
29: * dataEncipherment (3),
30: * keyAgreement (4),
31: * keyCertSign (5),
32: * cRLSign (6),
33: * encipherOnly (7),
34: * decipherOnly (8) }
35: * </pre>
36: */
37: public class KeyUsage extends DERBitString {
38: public static final int digitalSignature = (1 << 7);
39: public static final int nonRepudiation = (1 << 6);
40: public static final int keyEncipherment = (1 << 5);
41: public static final int dataEncipherment = (1 << 4);
42: public static final int keyAgreement = (1 << 3);
43: public static final int keyCertSign = (1 << 2);
44: public static final int cRLSign = (1 << 1);
45: public static final int encipherOnly = (1 << 0);
46: public static final int decipherOnly = (1 << 15);
47:
48: /**
49: * Basic constructor.
50: *
51: * @param usage - the bitwise OR of the Key Usage flags giving the
52: * allowed uses for the key.
53: * e.g. (KeyUsage.keyEncipherment | KeyUsage.dataEncipherment)
54: */
55: public KeyUsage(int usage) {
56: super (getBytes(usage), getPadBits(usage));
57: }
58:
59: public KeyUsage(DERBitString usage) {
60: super (usage.getBytes(), usage.getPadBits());
61: }
62:
63: public String toString() {
64: if (data.length == 1) {
65: return "KeyUsage: 0x" + Integer.toHexString(data[0] & 0xff);
66: }
67: return "KeyUsage: 0x"
68: + Integer.toHexString((data[1] & 0xff) << 8
69: | (data[0] & 0xff));
70: }
71: }
|