ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-BER-XS/XS.pm
Revision: 1.2
Committed: Fri Apr 19 16:23:00 2019 UTC (5 years, 1 month ago) by root
Branch: MAIN
Changes since 1.1: +7 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Convert::BER::XS - I<very> low level BER decoding
4
5 =head1 SYNOPSIS
6
7 use Convert::BER::XS ':all';
8
9 my $ber = ber_decode $buf
10 or die "unable to decode SNMP v1/v2c Message";
11
12 my $msg = ber_is_seq $ber
13 or die "SNMP message does not start with a sequence";
14
15 ber_is $msg->[0], ASN_UNIVERSAL, ASN_INTEGER32, 0
16 or die "SNMP message does not start with snmp version\n";
17
18 if ($msg->[0][BER_DATA] == 0 || $msg->[0][BER_DATA] == 1) {
19 # message is SNMP v1 or v2c
20
21 if (ber_is $msg->[2], ASN_CONTEXT, 4, 1) {
22 # message is v1 trap
23 my $trap = $msg->[2][BER_DATA];
24
25 # check whether trap is a cisco mac notification mac changed message
26 if (
27 (ber_is_oid $trap->[0], "1.3.6.1.4.1.9.9.215.2") # cmnInterfaceObjects
28 and (ber_is_i32 $trap->[2], 6)
29 and (ber_is_i32 $trap->[3], 1) # mac changed msg
30 ) {
31 ... and so on
32
33 =head1 DESCRIPTION
34
35 This module implements a I<very> low level BER/DER decoder, and in the
36 future, probably also an encoder (tell me if you want an encoder, this
37 might speed up the process of getting one).
38
39 If is tuned for low memory and high speed, while still maintaining some
40 level of user-friendlyness.
41
42 Currently, not much is documented, as this is an initial release to
43 reserve CPAN namespace, stay tuned for a few days.
44
45 =head2 RELATIONSHIP TO L<Convert::BER> and L<Convert::ASN1>
46
47 This module is I<not> the XS version of L<Convert::BER>, but a different
48 take at doing the same thing. I imagine this module would be a good base
49 for speeding up either fo these, or write a similar module, or write your
50 own LDAP or SNMP module for example.
51
52 =cut
53
54 package Convert::BER::XS;
55
56 use common::sense;
57
58 use XSLoader ();
59 use Exporter qw(import);
60
61 our $VERSION = '0.0';
62
63 XSLoader::load __PACKAGE__, $VERSION;
64
65 our %EXPORT_TAGS = (
66 all => [qw(
67 ber_decode
68 ber_is ber_is_seq ber_is_i32 ber_is_oid
69 BER_CLASS BER_TAG BER_CONSTRUCTED BER_DATA
70 ASN_BOOLEAN ASN_INTEGER32 ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OBJECT_IDENTIFIER ASN_TAG_BER ASN_TAG_MASK
71 ASN_CONSTRUCTED ASN_UNIVERSAL ASN_APPLICATION ASN_CONTEXT ASN_PRIVATE ASN_CLASS_MASK ASN_CLASS_SHIFT
72 ASN_SEQUENCE ASN_IPADDRESS ASN_COUNTER32 ASN_UNSIGNED32 ASN_TIMETICKS ASN_OPAQUE ASN_COUNTER64
73 )],
74 );
75
76 our @EXPORT_OK = map @$_, values %EXPORT_TAGS;
77
78 1;
79
80 =head1 AUTHOR
81
82 Marc Lehmann <schmorp@schmorp.de>
83 http://software.schmorp.de/pkg/Convert-BER-XS
84
85 =cut
86