From: Graham B. <gb...@us...> - 2002-03-25 09:06:22
|
Update of /cvsroot/perl-ldap/asn/t In directory usw-pr-cvs1:/tmp/cvs-serv20416/t Added Files: 10choice.t 11indef.t Log Message: Patch from Wolfgang Laun Fix bug in decode when there are nested CHOICEs Add tests t/10choice.t t/11indef.t --- NEW FILE: 10choice.t --- #!/usr/local/bin/perl # # Test the use of choices # use Convert::ASN1; BEGIN { require 't/funcs.pl' } print "1..7\n"; btest 1, $asn = Convert::ASN1->new; btest 2, $asn->prepare( <<'[TheEnd]' ) or warn $asn->error; Natural ::= CHOICE { prime Prime, product Product } Prime ::= [1] INTEGER Product ::= CHOICE { perfect Perfect, plain Plain } Perfect ::= [2] INTEGER Plain ::= [3] INTEGER Naturals ::= [4] SEQUENCE OF Natural List ::= [5] SEQUENCE { list Naturals } [TheEnd] my $nl = $asn->find( 'List' ); my $buf = $nl->encode( list => [ { prime => 13 }, { product => { perfect => 28 } }, { product => { plain => 42 } }, ] ); $result = pack( 'C*', 0xa5, 0x0b, 0xa4, 0x09, 0x81, 0x01, 0x0d, 0x82, 0x01, 0x1c, 0x83, 0x01, 0x2a, ); stest 3, $result, $buf; my $seq = $nl->decode( $buf ) or warn $asn->error; btest 4, defined( $seq ) && exists( $seq->{list} ); ntest 5, 13, $seq->{list}->[0]->{prime}; ntest 6, 28, $seq->{list}->[1]->{product}->{perfect}; ntest 7, 42, $seq->{list}->[2]->{product}->{plain}; --- NEW FILE: 11indef.t --- #!/usr/local/bin/perl # # Test that indefinite length encodings can be decoded # BEGIN { require 't/funcs.pl' } use Convert::ASN1; my @zz = ( 0, 0 ); print "1..7\n"; btest 1, $asn = Convert::ASN1->new; btest 2, $asn->prepare( <<'[TheEnd]' ); GroupOfThis ::= [1] OCTET STRING GroupOfThat ::= [2] OCTET STRING Item ::= [3] SEQUENCE { aGroup GroupOfThis OPTIONAL, bGroup GroupOfThat OPTIONAL } Items ::= [4] SEQUENCE OF Item List ::= [5] SEQUENCE { list Items } [TheEnd] my $buf = pack( 'C*', 0xa5, 0x80, 0xa4, 0x80, 0xa3, 0x80, 0x81, 0x03, ( ord('A') ) x 3, @zz, 0xa3, 0x80, 0x82, 0x03, ( ord('B') ) x 3, @zz, 0xa3, 0x80, 0x81, 0x03, ( ord('C') ) x 3, 0x82, 0x03, ( ord('D') ) x 3, @zz, @zz, @zz, ); my $nl = $asn->find( 'List' ); my $seq = $nl->decode( $buf ); btest 3, defined( $seq ) && exists( $seq->{list} ); stest 4, $seq->{list}->[0]->{aGroup}, 'AAA'; stest 5, $seq->{list}->[1]->{bGroup}, 'BBB'; stest 6, $seq->{list}->[2]->{aGroup}, 'CCC'; stest 7, $seq->{list}->[2]->{bGroup}, 'DDD'; |