1#!/usr/local/bin/perl
2
3#
4# Check whether the ANY DEFINED BY syntax is working
5#
6
7BEGIN { require './t/funcs.pl'}
8
9use Convert::ASN1;
10
11print "1..21\n";
12
13btest 1, $asn_str=Convert::ASN1->new or warn $asn->error;
14btest 2, $asn_str->prepare("string STRING") or warn $asn->error;
15btest 3, $asn_seq=Convert::ASN1->new or warn $asn->error;
16btest 4, $asn_seq->prepare(q(
17  SEQUENCE {
18    integer INTEGER,
19    str STRING
20  }
21)) or warn $asn_seq->error;
22
23btest 5, $asn = Convert::ASN1->new or warn $asn->error;
24btest 6, $asn->prepare(q(
25	type OBJECT IDENTIFIER,
26	content ANY DEFINED BY type
27)) or warn $asn->error;
28
29# Bogus OIDs - testing only!
30btest 7, $asn->registeroid("1.1.1.1",$asn_str);
31btest 8, $asn->registeroid("1.1.1.2",$asn_seq);
32
33# Encode the first type
34my $result = pack("C*", 0x06, 0x03, 0x29, 0x01, 0x01, 0x04, 0x0d, 0x4a, 0x75,
35		        0x73, 0x74, 0x20, 0x61, 0x20, 0x73, 0x74, 0x72, 0x69,
36                        0x6e, 0x67);
37
38stest 9, $result, $asn->encode(type => "1.1.1.1", content => {string=>"Just a string"});
39btest 10, $ret = $asn->decode($result) or warn $asn->error;
40stest 11, "Just a string", $ret->{content}->{string};
41
42# Now check the second
43
44$result = pack("C*", 0x06, 0x03, 0x29, 0x01, 0x02, 0x30, 0x11, 0x02,
45		     0x01, 0x01, 0x04, 0x0c, 0x61, 0x6e, 0x64, 0x20,
46		     0x61, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67);
47
48stest 12, $result, $asn->encode(type => "1.1.1.2",
49			        content => {integer=>1, str=>"and a string"});
50btest 13, $ret = $asn->decode($result) or warn $asn->error;
51ntest 14, 1, $ret->{content}->{integer};
52stest 15, "and a string", $ret->{content}->{str};
53
54# Decoding ANY with indefinite length must include the trailing terminator
55
56btest 16, $asn = Convert::ASN1->new or warn $asn->error;
57btest 17, $asn->prepare(q(
58        Test2 ::= ANY
59        Test1 ::= SEQUENCE OF ANY
60)) or warn $asn->error;
61
62$result = pack("H*","3080020109308002010900000000");
63
64btest 18, $ret = $asn->find('Test1')->decode($result);
65rtest 19, [pack("H*","020109"),pack("H*","30800201090000")], $ret;
66
67btest 20, $ret = $asn->find('Test2')->decode($result);
68stest 21, $result, $ret;
69