Debian Codegraph @

ssl-proxies/src/main/java/org/globus/gsi/util/KeyUsage.java

raw
1 /*
2 * Copyright 2013 NORDUnet A/S
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 * express or implied.
12 *
13 * See the License for the specific language governing permissions and limitations under the License.
14 */
15 package org.globus.gsi.util;
16
17 import org.bouncycastle.asn1.DERBitString;
18
19 public enum KeyUsage
20 {
21 DIGITAL_SIGNATURE(0),
22 NON_REPUDIATION(1),
23 KEY_ENCIPHERMENT(2),
24 DATA_ENCIPHERMENT(3),
25 KEY_AGREEMENT(4),
26 KEY_CERTSIGN(5),
27 CRL_SIGN(6),
28 ENCIPHER_ONLY(7),
29 DECIPHER_ONLY(8);
30
31 private int bit;
32
33 private KeyUsage(int bit) {
34 this.bit = bit;
35 }
36
37 public boolean isSet(DERBitString bits) {
38 byte[] bytes = bits.getBytes();
39 int length = (bytes.length * 8) - bits.getPadBits();
40 return (bit < length && ((bytes[bit / 8] & (0x80 >>> (bit % 8))) != 0));
41 }
42 }