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 76 77 78 79 80
|
#!/usr/local/bin/perl
#
# Complex test
#
use Convert::BER;
print "1..1\n";
@data = (
[
0,
{
fred => 'joe'
}
],
[
1,
{
beth => [
'jack',
'paul'
]
}
]
);
$ber = new Convert::BER;
$ber->encode(
SEQUENCE => [
INTEGER => 1,
SEQUENCE_OF => [ \@data,
# this sub will be called for each
# element in the array @data
# each element of @data is an array ref
# of which the first element is a number
ENUM => sub { $_[0]->[0] },
# this sub will be called for each
# element in the array @data
# each element of @data is an array ref
# of which the second element is a hashref
SEQUENCE_OF => [ sub { $_[0]->[1] },
# this sub will be called for each
# key in the hashref returned by the sub above
# $_[0] will be the hashref, $_[1] will
# be the key being processed
STRING => sub { $_[1] },
SET => [
# Depending on whether the hashref entry
# contains a scalar or an array ref will
# determine how many strings are added
STRING => sub { $_[0]->[1]{$_[1]} }
]
]
]
]
);
my $result = pack("C*", 0x30, 0x30, 0x02, 0x01, 0x01, 0x30, 0x2B, 0x0A,
0x01, 0x00, 0x30, 0x0D, 0x04, 0x04, 0x66, 0x72,
0x65, 0x64, 0x31, 0x05, 0x04, 0x03, 0x6A, 0x6F,
0x65, 0x0A, 0x01, 0x01, 0x30, 0x14, 0x04, 0x04,
0x62, 0x65, 0x74, 0x68, 0x31, 0x0C, 0x04, 0x04,
0x6A, 0x61, 0x63, 0x6B, 0x04, 0x04, 0x70, 0x61,
0x75, 0x6C);
print "not "
unless $ber->buffer eq $result;
print "ok 1\n";
|