ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-BER-XS/XS.pm
(Generate patch)

Comparing Convert-BER-XS/XS.pm (file contents):
Revision 1.28 by root, Sat Apr 20 15:37:27 2019 UTC vs.
Revision 1.33 by root, Sat Apr 20 17:23:21 2019 UTC

8 8
9 my $ber = ber_decode $buf, $Convert::BER::XS::SNMP_PROFILE 9 my $ber = ber_decode $buf, $Convert::BER::XS::SNMP_PROFILE
10 or die "unable to decode SNMP message"; 10 or die "unable to decode SNMP message";
11 11
12 # The above results in a data structure consisting of 12 # The above results in a data structure consisting of
13 # (class, tag, # constructed, data) 13 # (class, tag, flags, data)
14 # tuples. Below is such a message, SNMPv1 trap 14 # tuples. Below is such a message, SNMPv1 trap
15 # with a Cisco mac change notification. 15 # with a Cisco mac change notification.
16 # Did you know that Cisco is in the news almost 16 # Did you know that Cisco is in the news almost
17 # every week because of some backdoor password 17 # every week because of some backdoor password
18 # or other extremely stupid security bug? 18 # or other extremely stupid security bug?
134 134
135Constants only relevant to SNMP. These are the tag values used by SNMP in 135Constants only relevant to SNMP. These are the tag values used by SNMP in
136the C<ASN_APPLICATION> namespace and have the exact numerical value as in 136the C<ASN_APPLICATION> namespace and have the exact numerical value as in
137BER/RFC 2578. 137BER/RFC 2578.
138 138
139 SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64 139 SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_GAUGE32
140 SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64
140 141
141=item C<:decode> 142=item C<:decode>
142 143
143C<ber_decode> and the match helper functions: 144C<ber_decode> and the match helper functions:
144 145
303a ease-of-use exception, they usually also accept C<undef> instead of a 304a ease-of-use exception, they usually also accept C<undef> instead of a
304tuple reference, in which case they silently fail to match. 305tuple reference, in which case they silently fail to match.
305 306
306=over 307=over
307 308
308=item $bool = ber_is $tuple, $class, $tag, $constructed, $data 309=item $bool = ber_is $tuple, $class, $tag, $flags, $data
309 310
310This takes a BER C<$tuple> and matches its elements against the provided 311This takes a BER C<$tuple> and matches its elements against the provided
311values, all of which are optional - values that are either missing or 312values, all of which are optional - values that are either missing or
312C<undef> will be ignored, the others will be matched exactly (e.g. as if 313C<undef> will be ignored, the others will be matched exactly (e.g. as if
313you used C<==> or C<eq> (for C<$data>)). 314you used C<==> or C<eq> (for C<$data>)).
393use Exporter qw(import); 394use Exporter qw(import);
394 395
395our $VERSION; 396our $VERSION;
396 397
397BEGIN { 398BEGIN {
398 $VERSION = 0.8; 399 $VERSION = 0.9;
399 XSLoader::load __PACKAGE__, $VERSION; 400 XSLoader::load __PACKAGE__, $VERSION;
400} 401}
401 402
402our %EXPORT_TAGS = ( 403our %EXPORT_TAGS = (
403 const_index => [qw( 404 const_index => [qw(
417 BER_TYPE_BYTES BER_TYPE_UTF8 BER_TYPE_UCS2 BER_TYPE_UCS4 BER_TYPE_INT 418 BER_TYPE_BYTES BER_TYPE_UTF8 BER_TYPE_UCS2 BER_TYPE_UCS4 BER_TYPE_INT
418 BER_TYPE_OID BER_TYPE_RELOID BER_TYPE_NULL BER_TYPE_BOOL BER_TYPE_REAL 419 BER_TYPE_OID BER_TYPE_RELOID BER_TYPE_NULL BER_TYPE_BOOL BER_TYPE_REAL
419 BER_TYPE_IPADDRESS BER_TYPE_CROAK 420 BER_TYPE_IPADDRESS BER_TYPE_CROAK
420 )], 421 )],
421 const_snmp => [qw( 422 const_snmp => [qw(
422 SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64 423 SNMP_IPADDRESS SNMP_COUNTER32 SNMP_GAUGE32 SNMP_UNSIGNED32
424 SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64
423 )], 425 )],
424 decode => [qw( 426 decode => [qw(
425 ber_decode 427 ber_decode
426 ber_is ber_is_seq ber_is_int ber_is_oid 428 ber_is ber_is_seq ber_is_int ber_is_oid
427 )], 429 )],
582C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard 584C<BER_TYPE_BYTES>. When you don't want that but instead prefer a hard
583error for some types, then C<BER_TYPE_CROAK> is for you. 585error for some types, then C<BER_TYPE_CROAK> is for you.
584 586
585=back 587=back
586 588
589=head2 Example Profile
590
591The following creates a profile suitable for SNMP - it's exactly identical
592to the C<$Convert::BER::XS::SNMP_PROFILE> profile.
593
594 our $SNMP_PROFILE = new Convert::BER::XS::Profile;
595
596 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS);
597 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT);
598 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT);
599 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT);
600 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS);
601 $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT);
602
587=cut 603=cut
588 604
589our $DEFAULT_PROFILE = new Convert::BER::XS::Profile; 605our $DEFAULT_PROFILE = new Convert::BER::XS::Profile;
590our $SNMP_PROFILE = new Convert::BER::XS::Profile; 606
607$DEFAULT_PROFILE->_set_default;
591 608
592# additional SNMP application types 609# additional SNMP application types
610our $SNMP_PROFILE = new Convert::BER::XS::Profile;
611
593$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS); 612$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS);
594$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT); 613$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT);
595$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT); 614$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT);
596$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT); 615$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_TIMETICKS , BER_TYPE_INT);
597$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS); 616$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_OPAQUE , BER_TYPE_IPADDRESS);
598$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT); 617$SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER64 , BER_TYPE_INT);
599 618
600$DEFAULT_PROFILE->_set_default;
601
6021; 6191;
603 620
604=head2 LIMITATIONS/NOTES 621=head2 LIMITATIONS/NOTES
605 622
606This module can only en-/decode 64 bit signed and unsigned integers, and 623This module can only en-/decode 64 bit signed and unsigned integers, and
619Constructed strings are decoded just fine, but there should be a way to 636Constructed strings are decoded just fine, but there should be a way to
620join them for convenience. 637join them for convenience.
621 638
622REAL values are not supported and will currently croak. 639REAL values are not supported and will currently croak.
623 640
641The encoder and decoder tend to accept more formats than should be
642strictly supported.
643
624This module has undergone little to no testing so far. 644This module has undergone little to no testing so far.
625 645
626=head2 ITHREADS SUPPORT 646=head2 ITHREADS SUPPORT
627 647
628This module is unlikely to work when the (officially discouraged) ithreads 648This module is unlikely to work when the (officially discouraged) ithreads

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines