package org.bouncycastle.asn1.test;

import org.bouncycastle.util.test.Test;
import org.bouncycastle.util.test.TestResult;
import org.bouncycastle.util.test.SimpleTestResult;
import org.bouncycastle.asn1.x509.KeyUsage;

public class BitStringTest
    implements Test
{
    public TestResult perform()
    {
        KeyUsage k = new KeyUsage(KeyUsage.digitalSignature);
        if ((k.getBytes()[0] != (byte)KeyUsage.digitalSignature) || (k.getPadBits() != 7))
        {
            return new SimpleTestResult(false, getName() + ": failed digitalSignature");
        }
        
        k = new KeyUsage(KeyUsage.nonRepudiation);
        if ((k.getBytes()[0] != (byte)KeyUsage.nonRepudiation) || (k.getPadBits() != 6))
        {
            return new SimpleTestResult(false, getName() + ": failed nonRepudiation");
        }
        
        k = new KeyUsage(KeyUsage.keyEncipherment);
        if ((k.getBytes()[0] != (byte)KeyUsage.keyEncipherment) || (k.getPadBits() != 5))
        {
            return new SimpleTestResult(false, getName() + ": failed keyEncipherment");
        }
        
        k = new KeyUsage(KeyUsage.cRLSign);
        if ((k.getBytes()[0] != (byte)KeyUsage.cRLSign)  || (k.getPadBits() != 1))
        {
            return new SimpleTestResult(false, getName() + ": failed cRLSign");
        }
        
        k = new KeyUsage(KeyUsage.decipherOnly);
        if ((k.getBytes()[1] != (byte)(KeyUsage.decipherOnly >> 8))  || (k.getPadBits() != 7))
        {
            return new SimpleTestResult(false, getName() + ": failed decipherOnly");
        }
        
        return new SimpleTestResult(true, getName() + ": Okay");
    }

    public String getName()
    {
        return "BitString";
    }

    public static void main(
        String[] args)
    {
        BitStringTest    test = new BitStringTest();
        TestResult      result = test.perform();

        System.out.println(result);
    }
}

@@ -41,39 +41,156 @@
 ort 
-org.bouncycastle.util.test.Test
+java.io.IOException;%0A%0Aimport org.bouncycastle.asn1.ASN1Object;%0Aimport org.bouncycastle.asn1.DERBitString;%0Aimport org.bouncycastle.asn1.x509.KeyUsage
 ;%0Aim
@@ -221,16 +221,22 @@
 il.test.
+Simple
 TestResu
@@ -269,39 +269,27 @@
 e.util.test.
-SimpleTestResul
+Tes
 t;%0Aimport or
@@ -303,34 +303,36 @@
 ycastle.
-asn1.x509.KeyUsage
+util.test.TestResult
 ;%0A%0Apubli
@@ -1680,32 +1680,33 @@
 ;%0A        %7D%0A
+%0A
         
 %0A        ret
@@ -1685,32 +1685,304 @@
      %7D%0A%0A        
+// test for zero length bit string%0A        try%0A        %7B%0A            ASN1Object.fromByteArray(new DERBitString(new byte%5B0%5D, 0).getEncoded());%0A        %7D%0A        catch (IOException e)%0A        %7B%0A            return new SimpleTestResult(false, getName() + %22: %22 + e);%0A        %7D%0A
 %0A        return 

test for zero length string