01: package org.bouncycastle.asn1.test;
02:
03: import org.bouncycastle.util.test.Test;
04: import org.bouncycastle.util.test.TestResult;
05: import org.bouncycastle.util.test.SimpleTestResult;
06: import org.bouncycastle.asn1.x509.KeyUsage;
07:
08: public class BitStringTest implements Test {
09: public TestResult perform() {
10: KeyUsage k = new KeyUsage(KeyUsage.digitalSignature);
11: if ((k.getBytes()[0] != (byte) KeyUsage.digitalSignature)
12: || (k.getPadBits() != 7)) {
13: return new SimpleTestResult(false, getName()
14: + ": failed digitalSignature");
15: }
16:
17: k = new KeyUsage(KeyUsage.nonRepudiation);
18: if ((k.getBytes()[0] != (byte) KeyUsage.nonRepudiation)
19: || (k.getPadBits() != 6)) {
20: return new SimpleTestResult(false, getName()
21: + ": failed nonRepudiation");
22: }
23:
24: k = new KeyUsage(KeyUsage.keyEncipherment);
25: if ((k.getBytes()[0] != (byte) KeyUsage.keyEncipherment)
26: || (k.getPadBits() != 5)) {
27: return new SimpleTestResult(false, getName()
28: + ": failed keyEncipherment");
29: }
30:
31: k = new KeyUsage(KeyUsage.cRLSign);
32: if ((k.getBytes()[0] != (byte) KeyUsage.cRLSign)
33: || (k.getPadBits() != 1)) {
34: return new SimpleTestResult(false, getName()
35: + ": failed cRLSign");
36: }
37:
38: k = new KeyUsage(KeyUsage.decipherOnly);
39: if ((k.getBytes()[1] != (byte) (KeyUsage.decipherOnly >> 8))
40: || (k.getPadBits() != 7)) {
41: return new SimpleTestResult(false, getName()
42: + ": failed decipherOnly");
43: }
44:
45: return new SimpleTestResult(true, getName() + ": Okay");
46: }
47:
48: public String getName() {
49: return "BitString";
50: }
51:
52: public static void main(String[] args) {
53: BitStringTest test = new BitStringTest();
54: TestResult result = test.perform();
55:
56: System.out.println(result);
57: }
58: }
|