1
package org.bouncycastle.asn1.test;
3
import org.bouncycastle.asn1.ASN1InputStream;
4
import org.bouncycastle.asn1.ASN1TaggedObject;
5
import org.bouncycastle.asn1.DERApplicationSpecific;
6
import org.bouncycastle.asn1.ASN1Object;
7
import org.bouncycastle.util.encoders.Base64;
8
import org.bouncycastle.util.encoders.Hex;
9
import org.bouncycastle.util.test.SimpleTest;
11
import java.io.IOException;
12
import java.security.SecureRandom;
21
byte[] longTagged = Base64.decode(
22
"ZSRzIp8gEEZFRENCQTk4NzY1NDMyMTCfIQwyMDA2MDQwMTEyMzSUCCAFERVz"
23
+ "A4kCAHEXGBkalAggBRcYGRqUCCAFZS6QAkRFkQlURUNITklLRVKSBQECAwQF"
24
+ "kxAREhMUFRYXGBkalAggBREVcwOJAgBxFxgZGpQIIAUXGBkalAggBWUukAJE"
25
+ "RZEJVEVDSE5JS0VSkgUBAgMEBZMQERITFBUWFxgZGpQIIAURFXMDiQIAcRcY"
26
+ "GRqUCCAFFxgZGpQIIAVlLpACREWRCVRFQ0hOSUtFUpIFAQIDBAWTEBESExQV"
27
+ "FhcYGRqUCCAFERVzA4kCAHEXGBkalAggBRcYGRqUCCAFFxgZGpQIIAUXGBka"
30
byte[] longAppSpecificTag = Hex.decode("5F610101");
32
public String getName()
37
public void performTest()
40
ASN1InputStream aIn = new ASN1InputStream(longTagged);
42
DERApplicationSpecific app = (DERApplicationSpecific)aIn.readObject();
44
aIn = new ASN1InputStream(app.getContents());
46
app = (DERApplicationSpecific)aIn.readObject();
48
aIn = new ASN1InputStream(app.getContents());
50
ASN1TaggedObject tagged = (ASN1TaggedObject)aIn.readObject();
52
if (tagged.getTagNo() != 32)
54
fail("unexpected tag value found - not 32");
57
tagged = (ASN1TaggedObject)ASN1Object.fromByteArray(tagged.getEncoded());
59
if (tagged.getTagNo() != 32)
61
fail("unexpected tag value found on recode - not 32");
64
tagged = (ASN1TaggedObject)aIn.readObject();
66
if (tagged.getTagNo() != 33)
68
fail("unexpected tag value found - not 33");
71
tagged = (ASN1TaggedObject)ASN1Object.fromByteArray(tagged.getEncoded());
73
if (tagged.getTagNo() != 33)
75
fail("unexpected tag value found on recode - not 33");
78
aIn = new ASN1InputStream(longAppSpecificTag);
80
app = (DERApplicationSpecific)aIn.readObject();
82
if (app.getApplicationTag() != 97)
84
fail("incorrect tag number read");
87
app = (DERApplicationSpecific)ASN1Object.fromByteArray(app.getEncoded());
89
if (app.getApplicationTag() != 97)
91
fail("incorrect tag number read on recode");
94
SecureRandom sr = new SecureRandom();
95
for (int i = 0; i < 100; ++i)
97
int testTag = sr.nextInt() >>> (1 + (sr.nextInt() >>> 1) % 26);
98
app = new DERApplicationSpecific(testTag, new byte[]{ 1 });
99
app = (DERApplicationSpecific)ASN1Object.fromByteArray(app.getEncoded());
101
if (app.getApplicationTag() != testTag)
103
fail("incorrect tag number read on recode (random test value: " + testTag + ")");
108
public static void main(
111
runTest(new TagTest());