FileDocCategorySizeDatePackage
Asn1SequenceTest.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)10760Wed Oct 01 10:56:10 BST 2008org.bouncycastle.sasn1.test

Asn1SequenceTest

public class Asn1SequenceTest extends junit.framework.TestCase
deprecated
obsolete test case

Fields Summary
private static final byte[]
seqData
private static final byte[]
nestedSeqData
private static final byte[]
expTagSeqData
private static final byte[]
implTagSeqData
private static final byte[]
nestedSeqExpTagData
private static final byte[]
nestedSeqImpTagData
private static final byte[]
berSeqData
private static final byte[]
berDerNestedSeqData
private static final byte[]
berNestedSeqData
private static final byte[]
berExpTagSeqData
Constructors Summary
Methods Summary
public static junit.framework.Testsuite()

        return new TestSuite(Asn1SequenceTest.class);
    
public voidtestBerExplicitTaggedSequenceWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       BerSequenceGenerator  seqGen = new BerSequenceGenerator(bOut, 1, true);
       
       seqGen.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen.addObject(new Asn1ObjectIdentifier("1.1"));
       
       seqGen.close();
      
       assertTrue("explicit BER tag writing test failed.", Arrays.equals(berExpTagSeqData, bOut.toByteArray()));
    
public voidtestBerReading()

        Asn1InputStream aIn = new Asn1InputStream(berSeqData);
        
        Asn1Sequence    seq = (Asn1Sequence)aIn.readObject();
        Object          o = null;
        int             count = 0;
        
        assertNotNull("null sequence returned", seq);
        
        while ((o = seq.readObject()) != null)
        {
            switch (count)
            {
            case 0:
                assertTrue(o instanceof Asn1Integer);
                break;
            case 1:
                assertTrue(o instanceof Asn1ObjectIdentifier);
                break;
            }
            count++;
        }
        
        assertEquals("wrong number of objects in sequence", 2, count);
    
public voidtestBerWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       BerSequenceGenerator  seqGen = new BerSequenceGenerator(bOut);
       
       seqGen.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen.addObject(new Asn1ObjectIdentifier("1.1"));
       
       seqGen.close();
       
       assertTrue("basic BER writing test failed.", Arrays.equals(berSeqData, bOut.toByteArray()));
    
public voidtestDerExplicitTaggedSequenceWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       DerSequenceGenerator  seqGen = new DerSequenceGenerator(bOut, 1, true);
       
       seqGen.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen.addObject(new Asn1ObjectIdentifier("1.1"));
       
       seqGen.close();

       assertTrue("explicit tag writing test failed.", Arrays.equals(expTagSeqData, bOut.toByteArray()));
    
public voidtestDerImplicitTaggedSequenceWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       DerSequenceGenerator  seqGen = new DerSequenceGenerator(bOut, 1, false);
       
       seqGen.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen.addObject(new Asn1ObjectIdentifier("1.1"));
       
       seqGen.close();

       assertTrue("implicit tag writing test failed.", Arrays.equals(implTagSeqData, bOut.toByteArray()));
    
public voidtestDerReading()

        Asn1InputStream aIn = new Asn1InputStream(seqData);
        
        Asn1Sequence    seq = (Asn1Sequence)aIn.readObject();
        Object          o = null;
        int             count = 0;
        
        assertNotNull("null sequence returned", seq);
        
        while ((o = seq.readObject()) != null)
        {
            switch (count)
            {
            case 0:
                assertTrue(o instanceof Asn1Integer);
                break;
            case 1:
                assertTrue(o instanceof Asn1ObjectIdentifier);
                break;
            }
            count++;
        }
        
        assertEquals("wrong number of objects in sequence", 2, count);
    
public voidtestDerWriting()

    
      
         
    
       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       DerSequenceGenerator  seqGen = new DerSequenceGenerator(bOut);
       
       seqGen.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen.addObject(new Asn1ObjectIdentifier("1.1"));
       
       seqGen.close();

       assertTrue("basic DER writing test failed.", Arrays.equals(seqData, bOut.toByteArray()));
    
public voidtestNestedBerDerReading()

        testNestedReading(berDerNestedSeqData);
    
public voidtestNestedBerDerWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       BerSequenceGenerator  seqGen1 = new BerSequenceGenerator(bOut);
       
       seqGen1.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen1.addObject(new Asn1ObjectIdentifier("1.1"));
       
       DerSequenceGenerator seqGen2 = new DerSequenceGenerator(seqGen1.getRawOutputStream());
       
       seqGen2.addObject(new Asn1Integer(BigInteger.valueOf(1)));
       
       seqGen2.close();
       
       seqGen1.close();

       assertTrue("nested BER/DER writing test failed.", Arrays.equals(berDerNestedSeqData, bOut.toByteArray()));
    
public voidtestNestedBerReading()

        testNestedReading(berNestedSeqData);
    
public voidtestNestedBerWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       BerSequenceGenerator  seqGen1 = new BerSequenceGenerator(bOut);
       
       seqGen1.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen1.addObject(new Asn1ObjectIdentifier("1.1"));
       
       BerSequenceGenerator seqGen2 = new BerSequenceGenerator(seqGen1.getRawOutputStream());
       
       seqGen2.addObject(new Asn1Integer(BigInteger.valueOf(1)));
       
       seqGen2.close();
       
       seqGen1.close();

       assertTrue("nested BER writing test failed.", Arrays.equals(berNestedSeqData, bOut.toByteArray()));
    
public voidtestNestedDerReading()

        testNestedReading(nestedSeqData);
    
public voidtestNestedDerWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       DerSequenceGenerator  seqGen1 = new DerSequenceGenerator(bOut);
       
       seqGen1.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen1.addObject(new Asn1ObjectIdentifier("1.1"));
       
       DerSequenceGenerator seqGen2 = new DerSequenceGenerator(seqGen1.getRawOutputStream());
       
       seqGen2.addObject(new Asn1Integer(BigInteger.valueOf(1)));
       
       seqGen2.close();
       
       seqGen1.close();

       assertTrue("nested DER writing test failed.", Arrays.equals(nestedSeqData, bOut.toByteArray()));
    
public voidtestNestedExplicitTagDerWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       DerSequenceGenerator  seqGen1 = new DerSequenceGenerator(bOut);
       
       seqGen1.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen1.addObject(new Asn1ObjectIdentifier("1.1"));
       
       DerSequenceGenerator seqGen2 = new DerSequenceGenerator(seqGen1.getRawOutputStream(), 1, true);
       
       seqGen2.addObject(new Asn1Integer(BigInteger.valueOf(1)));
       
       seqGen2.close();
       
       seqGen1.close();

       assertTrue("nested explicit tagged DER writing test failed.", Arrays.equals(nestedSeqExpTagData, bOut.toByteArray()));
    
public voidtestNestedImplicitTagDerWriting()

       ByteArrayOutputStream bOut = new ByteArrayOutputStream();
       DerSequenceGenerator  seqGen1 = new DerSequenceGenerator(bOut);
       
       seqGen1.addObject(new Asn1Integer(BigInteger.valueOf(0)));
       
       seqGen1.addObject(new Asn1ObjectIdentifier("1.1"));
       
       DerSequenceGenerator seqGen2 = new DerSequenceGenerator(seqGen1.getRawOutputStream(), 1, false);
       
       seqGen2.addObject(new Asn1Integer(BigInteger.valueOf(1)));
       
       seqGen2.close();
       
       seqGen1.close();

       assertTrue("nested implicit tagged DER writing test failed.", Arrays.equals(nestedSeqImpTagData, bOut.toByteArray()));
    
public voidtestNestedReading(byte[] data)

        Asn1InputStream aIn = new Asn1InputStream(data);
        
        Asn1Sequence    seq = (Asn1Sequence)aIn.readObject();
        Object          o = null;
        int             count = 0;
        
        assertNotNull("null sequence returned", seq);
        
        while ((o = seq.readObject()) != null)
        {
            switch (count)
            {
            case 0:
                assertTrue(o instanceof Asn1Integer);
                break;
            case 1:
                assertTrue(o instanceof Asn1ObjectIdentifier);
                break;
            case 2:
                assertTrue(o instanceof Asn1Sequence);
                
                Asn1Sequence s = (Asn1Sequence)o;
                
                s.readObject();
                
                break;
            }
            count++;
        }
        
        assertEquals("wrong number of objects in sequence", 3, count);