All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.bouncycastle.asn1.test.InputStreamTest Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.bouncycastle.asn1.test;

import java.io.IOException;

import com.fitbur.bouncycastle.asn1.ASN1InputStream;
import com.fitbur.bouncycastle.util.test.SimpleTest;

public class InputStreamTest 
    extends SimpleTest
{
    private static final byte[] outOfBoundsLength = new byte[] { (byte)0x30, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff };
    private static final byte[] negativeLength = new byte[] { (byte)0x30, (byte)0x84, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff };
    private static final byte[] outsideLimitLength = new byte[] { (byte)0x30, (byte)0x83, (byte)0x0f, (byte)0xff, (byte)0xff };
    
    
    public String getName()
    {
        return "InputStream";
    }
    
    public void performTest() 
        throws Exception
    {
        ASN1InputStream aIn = new ASN1InputStream(outOfBoundsLength);
        
        try
        {
            aIn.readObject();
            fail("out of bounds length not com.fitburtected.");
        }
        catch (IOException e)
        {
            if (!e.getMessage().startsWith("DER length more than 4 bytes"))
            {
                fail("wrong exception: " + e.getMessage());
            }
        }
        
        aIn = new ASN1InputStream(negativeLength);
        
        try
        {
            aIn.readObject();
            fail("negative length not com.fitburtected.");
        }
        catch (IOException e)
        {
            if (!e.getMessage().equals("corrupted stream - negative length found"))
            {
                fail("wrong exception: " + e.getMessage());
            }
        }
        
        aIn = new ASN1InputStream(outsideLimitLength);
        
        try
        {
            aIn.readObject();
            fail("outside limit length not com.fitburtected.");
        }
        catch (IOException e)
        {
            if (!e.getMessage().equals("corrupted stream - out of bounds length found"))
            {
                fail("wrong exception: " + e.getMessage());
            }
        }
    }

    public static void main(
        String[]    args)
    {
        runTest(new InputStreamTest());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy