inputstreamtest.java

来自「J2ME加密算法的代码!里面包括常用的算法」· Java 代码 · 共 76 行

JAVA
76
字号
package org.bouncycastle.asn1.test;import java.io.IOException;import org.bouncycastle.asn1.ASN1InputStream;import org.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 detected.");        }        catch (IOException e)        {            if (!e.getMessage().equals("DER length more than 4 bytes"))            {                fail("wrong exception: " + e.getMessage());            }        }                aIn = new ASN1InputStream(negativeLength);                try        {            aIn.readObject();            fail("negative length not detected.");        }        catch (IOException e)        {            if (!e.getMessage().equals("corrupted steam - negative length found"))            {                fail("wrong exception: " + e.getMessage());            }        }                aIn = new ASN1InputStream(outsideLimitLength);                try        {            aIn.readObject();            fail("outside limit length not detected.");        }        catch (IOException e)        {            if (!e.getMessage().equals("corrupted steam - out of bounds length found"))            {                fail("wrong exception: " + e.getMessage());            }        }    }    public static void main(        String[]    args)    {        runTest(new InputStreamTest());    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?