1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package org.spongycastle.asn1.test;
import java.io.IOException;
import org.spongycastle.asn1.ASN1InputStream;
import org.spongycastle.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().startsWith("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 stream - 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 stream - out of bounds length found"))
{
fail("wrong exception: " + e.getMessage());
}
}
}
public static void main(
String[] args)
{
runTest(new InputStreamTest());
}
}
|