… | |
… | |
108 | BER_CLASS BER_TAG BER_FLAGS BER_DATA |
108 | BER_CLASS BER_TAG BER_FLAGS BER_DATA |
109 | |
109 | |
110 | =item C<:const_asn> |
110 | =item C<:const_asn> |
111 | |
111 | |
112 | ASN class values (these are C<0>, C<1>, C<2> and C<3>, respectively - |
112 | ASN class values (these are C<0>, C<1>, C<2> and C<3>, respectively - |
113 | exactly thw two topmost bits from the identifier octet shifted 6 bits to |
113 | exactly the two topmost bits from the identifier octet shifted 6 bits to |
114 | the right): |
114 | the right): |
115 | |
115 | |
116 | ASN_UNIVERSAL ASN_APPLICATION ASN_CONTEXT ASN_PRIVATE |
116 | ASN_UNIVERSAL ASN_APPLICATION ASN_CONTEXT ASN_PRIVATE |
117 | |
117 | |
118 | ASN tag values (some of which are aliases, such as C<ASN_OID>). Their |
118 | ASN tag values (some of which are aliases, such as C<ASN_OID>). Their |
… | |
… | |
296 | Also, since BER is self-delimited, this can be used to decode multiple BER |
296 | Also, since BER is self-delimited, this can be used to decode multiple BER |
297 | values joined together. |
297 | values joined together. |
298 | |
298 | |
299 | =item $bindata = ber_encode $tuple[, $profile] |
299 | =item $bindata = ber_encode $tuple[, $profile] |
300 | |
300 | |
301 | Encodes the BER tuple into a BER/DER data structure. AS with |
301 | Encodes the BER tuple into a BER/DER data structure. As with |
302 | Cyber_decode>, an optional profile can be given. |
302 | Cyber_decode>, an optional profile can be given. |
303 | |
303 | |
304 | The encoded data should be both BER and DER ("shortest form") compliant |
304 | The encoded data should be both BER and DER ("shortest form") compliant |
305 | unless the input says otherwise (e.g. it uses constructed strings). |
305 | unless the input says otherwise (e.g. it uses constructed strings). |
306 | |
306 | |
… | |
… | |
412 | use Exporter qw(import); |
412 | use Exporter qw(import); |
413 | |
413 | |
414 | our $VERSION; |
414 | our $VERSION; |
415 | |
415 | |
416 | BEGIN { |
416 | BEGIN { |
417 | $VERSION = 1.1; |
417 | $VERSION = 1.11; |
418 | XSLoader::load __PACKAGE__, $VERSION; |
418 | XSLoader::load __PACKAGE__, $VERSION; |
419 | } |
419 | } |
420 | |
420 | |
421 | our %EXPORT_TAGS = ( |
421 | our %EXPORT_TAGS = ( |
422 | const_index => [qw( |
422 | const_index => [qw( |
… | |
… | |
468 | |
468 | |
469 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
469 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
470 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
470 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
471 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
471 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
472 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
472 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
473 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
|
|
474 | |
473 | |
475 | =head2 DEBUGGING |
474 | =head2 DEBUGGING |
476 | |
475 | |
477 | To aid debugging, you cna call the C<ber_dump> function to print a "nice" |
476 | To aid debugging, you cna call the C<ber_dump> function to print a "nice" |
478 | representation to STDOUT. |
477 | representation to STDOUT. |
479 | |
478 | |
480 | =over |
479 | =over |
481 | |
480 | |
482 | =item ber_dump $tuple[, $profile[, $prefix]] |
481 | =item ber_dump $tuple[, $profile[, $prefix]] |
483 | |
482 | |
484 | In addition to specifying the BER C<$tuple> to dump, youc an also specify |
483 | In addition to specifying the BER C<$tuple> to dump, you can also specify |
485 | a C<$profile> and a C<$prefix> string that is printed in front of each line. |
484 | a C<$profile> and a C<$prefix> string that is printed in front of each line. |
486 | |
485 | |
487 | If C<$profile> is C<$Convert::BER::XS::SNMP_PROFILE>, then C<ber_dump> |
486 | If C<$profile> is C<$Convert::BER::XS::SNMP_PROFILE>, then C<ber_dump> |
488 | will try to improve its output for SNMP data. |
487 | will try to improve its output for SNMP data. |
489 | |
488 | |
… | |
… | |
496 | Example output: |
495 | Example output: |
497 | |
496 | |
498 | SEQUENCE |
497 | SEQUENCE |
499 | | OCTET_STRING bytes 800063784300454045045400000001 |
498 | | OCTET_STRING bytes 800063784300454045045400000001 |
500 | | OCTET_STRING bytes |
499 | | OCTET_STRING bytes |
501 | | CONTEXT (7) bytes CONSTRUCTED |
500 | | CONTEXT (7) CONSTRUCTED |
502 | | | INTEGER int 1058588941 |
501 | | | INTEGER int 1058588941 |
503 | | | INTEGER int 0 |
502 | | | INTEGER int 0 |
504 | | | INTEGER int 0 |
503 | | | INTEGER int 0 |
505 | | | SEQUENCE |
504 | | | SEQUENCE |
506 | | | | SEQUENCE |
505 | | | | SEQUENCE |
… | |
… | |
549 | $class =~ s/^ASN_//; |
548 | $class =~ s/^ASN_//; |
550 | $tag =~ s/^(ASN_|SNMP_)//; |
549 | $tag =~ s/^(ASN_|SNMP_)//; |
551 | $type =~ s/^BER_TYPE_//; |
550 | $type =~ s/^BER_TYPE_//; |
552 | |
551 | |
553 | if ($ber->[BER_FLAGS]) { |
552 | if ($ber->[BER_FLAGS]) { |
554 | printf "$indent%-16.16s %-6.6s CONSTRUCTED\n", $tag, lc $type; |
553 | printf "$indent%-16.16s\n", $tag; |
555 | &_ber_dump ($_, $profile, "$indent| ") |
554 | &_ber_dump ($_, $profile, "$indent| ") |
556 | for @$data; |
555 | for @$data; |
557 | } else { |
556 | } else { |
558 | if ($data =~ y/\x20-\x7e//c / (length $data || 1) > 0.2 or $data =~ /\x00./s) { |
557 | if ($data =~ y/\x20-\x7e//c / (length $data || 1) > 0.2 or $data =~ /\x00./s) { |
559 | # assume binary |
558 | # assume binary |
560 | $data = unpack "H*", $data; |
559 | $data = unpack "H*", $data; |
561 | } else { |
560 | } else { |
562 | $data =~ s/[^\x20-\x7e]/./g; |
561 | $data =~ s/[^\x20-\x7e]/./g; |
563 | $data = "\"$data\"" if $type =~ /string/i || !length $data; |
562 | $data = "\"$data\"" if $tag =~ /string/i || !length $data; |
564 | } |
563 | } |
565 | |
564 | |
566 | substr $data, 40, 1e9, "..." if 40 < length $data; |
565 | substr $data, 40, 1e9, "..." if 40 < length $data; |
567 | |
566 | |
568 | printf "$indent%-16.16s %-6.6s %s\n", $tag, lc $type, $data; |
567 | printf "$indent%-16.16s %-6.6s %s\n", $tag, lc $type, $data; |
… | |
… | |
733 | |
732 | |
734 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
733 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); |
735 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
734 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); |
736 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
735 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); |
737 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
736 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); |
738 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); |
737 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_BYTES); |
739 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
738 | $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); |
740 | |
739 | |
741 | =head2 LIMITATIONS/NOTES |
740 | =head2 LIMITATIONS/NOTES |
742 | |
741 | |
743 | This module can only en-/decode 64 bit signed and unsigned integers, and |
742 | This module can only en-/decode 64 bit signed and unsigned integers, and |