Convert-BER-XS

 view release on metacpan or  search on metacpan

t/04_longer.t  view on Meta::CPAN

BEGIN { $| = 1; print "1..60\n"; }

use common::sense;
use Convert::BER::XS ':all';

# finally, the "löonger" testcase

our $test;
sub ok($;$) {
   print $_[0] ? "" : "not ", "ok ", ++$test, " # $_[1]\n";
}

while (<DATA>) { # comment
   chop;
   chop (my $mode = readline DATA);
   my $hex = do { local $/ = "\n\n"; readline DATA };
   $hex =~ y/0-9a-f//cd;
   my $bin = pack "H*", $hex;

   my $emptyprofile = new Convert::BER::XS::Profile;

   $emptyprofile->set (ASN_UNIVERSAL, $_, BER_TYPE_BYTES) for 0..50;

   for my $profile (
      $Convert::BER::XS::DEFAULT_PROFILE,
      $Convert::BER::XS::SNMP_PROFILE,
      $emptyprofile,
      new Convert::BER::XS::Profile,
   ) {
      if ($mode eq "fail") {
         ok (!eval { ber_decode $bin, $profile; 1 }, "fail $_");
      } else {
	 my $ber = ber_decode $bin, $profile;
	 ok ($ber, "encode $_");

	 my $enc = ber_encode $ber, $profile;

	 ok ($mode eq "roundtrip" ? $enc eq $bin : 1, "decode $_");
      }
   }
}

__DATA__
# 512b-rsa-example-cert.der
roundtrip
3082 0212 3082 017b 0202 0dfa 300d 0609
2a86 4886 f70d 0101 0505 0030 819b 310b
3009 0603 5504 0613 024a 5031 0e30 0c06
0355 0408 1305 546f 6b79 6f31 1030 0e06
0355 0407 1307 4368 756f 2d6b 7531 1130
0f06 0355 040a 1308 4672 616e 6b34 4444
3118 3016 0603 5504 0b13 0f57 6562 4365
7274 2053 7570 706f 7274 3118 3016 0603
5504 0313 0f46 7261 6e6b 3444 4420 5765
6220 4341 3123 3021 0609 2a86 4886 f70d
0109 0116 1473 7570 706f 7274 4066 7261
6e6b 3464 642e 636f 6d30 1e17 0d31 3230
3832 3230 3532 3635 345a 170d 3137 3038
3231 3035 3236 3534 5a30 4a31 0b30 0906
0355 0406 1302 4a50 310e 300c 0603 5504
080c 0554 6f6b 796f 3111 300f 0603 5504
0a0c 0846 7261 6e6b 3444 4431 1830 1606
0355 0403 0c0f 7777 772e 6578 616d 706c
652e 636f 6d30 5c30 0d06 092a 8648 86f7
0d01 0101 0500 034b 0030 4802 4100 9bfc
6690 7984 42bb ab13 fd2b 7bf8 de15 12e5
f193 e306 8a7b b8b1 e19e 26bb 9501 bfe7
30ed 6485 02dd 1569 a834 b006 ec3f 353c
1e1b 2b8f fa8f 001b df07 c6ac 5307 0203



( run in 1.571 second using v1.01-cache-2.11-cpan-d7f47b0818f )