Convert-BER-XS

 view release on metacpan or  search on metacpan

XS.pm  view on Meta::CPAN

            $data = "\"$data\"" if $tag =~ /string/i || !length $data;
         }

         substr $data, 40, 1e9, "..." if 40 < length $data;

         printf "$indent%-16.16s %-6.6s %s\n", $tag, lc $type, $data;
      }
   }
}

sub ber_dump($;$$) {
   _ber_dump $_[0], $_[1] || $DEFAULT_PROFILE, $_[2];
}

=head1 PROFILES

While any BER data can be correctly encoded and decoded out of the box, it
can be inconvenient to have to manually decode some values into a "better"
format: for instance, SNMP TimeTicks values are decoded into the raw octet
strings of their BER representation, which is quite hard to decode. With
profiles, you can change which class/tag combinations map to which decoder

t/01_helper.t  view on Meta::CPAN

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

use common::sense;
use Convert::BER::XS qw(:encode :decode :const);

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

ok (ber_is [ASN_UNIVERSAL, ASN_INTEGER, 0, 5], ASN_UNIVERSAL, ASN_INTEGER,     0,     5);
ok (ber_is [ASN_UNIVERSAL, ASN_INTEGER, 0, 5], undef        , ASN_INTEGER,     0,     5);
ok (ber_is [ASN_UNIVERSAL, ASN_INTEGER, 0, 5], ASN_UNIVERSAL, undef      ,     0,     5);
ok (ber_is [ASN_UNIVERSAL, ASN_INTEGER, 0, 5], ASN_UNIVERSAL, ASN_INTEGER, undef,     5);
ok (ber_is [ASN_UNIVERSAL, ASN_INTEGER, 0, 5], ASN_UNIVERSAL, ASN_INTEGER,     0, undef);

ok (!ber_is [ASN_UNIVERSAL, ASN_INTEGER, 0, 5], ASN_UNIVERSAL, ASN_INTEGER,     0, 4);

t/02_simple.t  view on Meta::CPAN

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

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

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

sub fail {
   my ($hex, $match) = @_;

   y/ //d for $hex;

   ok (!eval { ber_decode pack "H*", $hex; 1 }, "# fail $hex");
   $@ =~ s/ at .*//s;

t/03_security.t  view on Meta::CPAN

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

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

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

my $uvsize = length pack "J", 0;

for (1..4) {
   for my $bit (0 .. 199) {
      # I wrote this at 4 in the morning. I am sure there must be a more
      # elegant way than this shit.
      my $c = "1" . join "", map int 2 * rand, 1 .. $bit;

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;

t/05_bugs.t  view on Meta::CPAN

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

# various bugs fixed after 1.0

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

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

my ($bin, $ber);

# length 127
$bin = ber_encode [0, ASN_OCTET_STRING,  0, "\x01" x 127];
ok ($bin =~ /^\x04\x7f\x01{127}/, unpack "H*", $bin);
$ber = ber_decode $bin;
ok (127 == length $ber->[BER_DATA]);

t/06_snmp.t  view on Meta::CPAN

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

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

$Convert::BER::XS::SNMP_PROFILE->_set_default;

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

sub fail {
   my ($hex, $match) = @_;

   y/ //d for $hex;

   ok (!eval { ber_decode pack "H*", $hex; 1 }, "# fail $hex");
   $@ =~ s/ at .*//s;



( run in 0.342 second using v1.01-cache-2.11-cpan-1f129e94a17 )