1BER(3)                User Contributed Perl Documentation               BER(3)
2
3
4

NAME

6       BER - Basic Encoding Rules (BER) of Abstract Syntax Notation One
7       (ASN.1)
8

SYNOPSIS

10           use BER;
11           $encoded = encode_sequence (encode_int (123), encode_string ("foo"));
12           ($i, $s) = decode_by_template ($encoded, "%{%i%s");
13           # $i will now be 123, $s the string "foo".
14

DESCRIPTION

16       This is a simple library to encode and decode data using the Basic
17       Encoding Rules (BER) of Abstract Syntax Notation One (ASN.1).  It does
18       not claim to be a complete implementation of the standard, but
19       implements enough of the BER standard to encode and decode SNMP
20       messages.
21

VARIABLES

23   $pretty_print_timeticks (default: 1)
24       If non-zero (the default), "pretty_print" will convert TimeTicks to
25       "human readable" strings containing days, hours, minutes and seconds.
26
27       If the variable is zero, "pretty_print" will simply return an unsigned
28       integer representing hundredths of seconds.  If you prefer this, bind
29       $pretty_print_timeticks to zero.
30
31   $errmsg - error message from last failed operation.
32       When they encounter errors, the routines in this module will generally
33       return "undef") and leave an informative error message in $errmsg).
34

METHODS

36   encode_int_0() - encode the integer 0.
37       This is functionally identical to encode_int(0).
38
39   encode_int() - encode an integer using the generic "integer" type tag.
40   encode_uinteger32() - encode an integer using the SNMP UInteger32 tag.
41   encode_counter32() - encode an integer using the SNMP Counter32 tag.
42   encode_counter64() - encode an integer using the SNMP Counter64 tag.
43   encode_gauge32() - encode an integer using the SNMP Gauge32 tag.
44   encode_oid() - encode an object ID, passed as a list of sub-IDs.
45           $encoded = encode_oid (1,3,6,1,...);
46
47   encode_null() - encode a null object.
48       This is used e.g. in binding lists for variables that don't have a
49       value (yet)
50
51   encode_sequence()
52   encode_tagged_sequence()
53           $encoded = encode_sequence (encoded1, encoded2, ...);
54           $encoded = encode_tagged_sequence (tag, encoded1, encoded2, ...);
55
56       Take already encoded values, and extend them to an encoded sequence.
57       "encoded_sequence" uses the generic sequence tag, while with
58       "encode_tagged_sequence" you can specify your own tag.
59
60   encode_string() - encode a Perl string as an OCTET STRING.
61   encode_ip_address() - encode an IPv4 address.
62       This can either be passed as a four-octet sequence in network byte
63       order, or as a text string in dotted-quad notation, e.g. "192.0.2.234".
64
65   encode_timeticks() - encode an integer as a "TimeTicks" object.
66       The integer should count hundredths of a second since the epoch defined
67       by "sysUpTime.0".
68
69   pretty_print() - convert an encoded byte sequence into human-readable form.
70       This function can be extended by registering pretty-printing methods
71       for specific type codes.  Most BER type codes used in SNMP already have
72       such methods pre-registered by default.  See "register_pretty_printer"
73       for how new methods can be added.
74
75   hex_string() - convert OCTET STRING to hexadecimal notation.
76   hex_string_of_type() - convert octet string to hex, and check type against
77       given tag.
78   decode_by_template() - decode complex object according to a template.
79           ($var1, ...) = decode_by_template ($pdu, $template, ...);
80
81       The template can contain various %X directives.  Some directives
82       consume additional arguments following the template itself.  Most
83       directives will cause values to be returned.  The values are returned
84       as a sequence in the order of the directives that generated them.
85
86       %{ - decode sequence.
87           This doesn't assign any return value, just checks and skips the
88           tag/length fields of the sequence.  By default, the tag should be
89           the generic sequence tag, but a tag can also be specified in the
90           directive.  The directive can either specify the tag as a prefix,
91           e.g. "%99{" will require a sequence tag of 99, or if the directive
92           is given as "%*{", the tag will be taken from the next argument.
93
94       %s - decode string
95       %i - decode integer
96       %u - decode unsigned integer
97       %O - decode Object ID (OID)
98       %A - decode IPv4 address
99       %@ - assigns the remaining undecoded part of the PDU to the next return
100       value.
101
102   decode_sequence() - Split sequence into components.
103           ($first, $rest) = decode_sequence ($pdu);
104
105       Checks whether the PDU has a sequence type tag and a plausible length
106       field.  Splits the initial element off the list, and returns both this
107       and the remainder of the PDU.
108
109   register_pretty_printer() - register pretty-printing methods for typecodes.
110       This function takes a hashref that specifies functions to call when the
111       specified value type is being printed.  It returns the number of
112       functions that were registered.
113

AUTHORS

115       Created by:  Simon Leinen  <simon.leinen@switch.ch>
116
117       Contributions and fixes by:
118
119       Andrzej Tobola <san@iem.pw.edu.pl>:  Added long String decode
120       Tobias Oetiker <tobi@oetiker.ch>:  Added 5 Byte Integer decode ...
121       Dave Rand <dlr@Bungi.com>:  Added "SysUpTime" decode
122       Philippe Simonet <sip00@vg.swissptt.ch>:  Support larger subids
123       Yufang HU <yhu@casc.com>:  Support even larger subids
124       Mike Mitchell <Mike.Mitchell@sas.com>: New generalized encode_int()
125       Mike Diehn <mdiehn@mindspring.net>: encode_ip_address()
126       Rik Hoorelbeke <rik.hoorelbeke@pandora.be>: encode_oid() fix
127       Brett T Warden <wardenb@eluminant.com>: pretty "UInteger32"
128       Bert Driehuis <driehuis@playbeing.org>: Handle SNMPv2 exception codes
129       Jakob Ilves (/IlvJa) <jakob.ilves@oracle.com>: PDU decoding
130       Jan Kasprzak <kas@informatics.muni.cz>: Fix for PDU syntax check
131       Milen Pavlov <milen@batmbg.com>: Recognize variant length for ints
132
134       Copyright (c) 1995-2009, Simon Leinen.
135
136       This program is free software; you can redistribute it under the
137       "Artistic License 2.0" included in this distribution (file "Artistic").
138
139
140
141perl v5.38.0                      2023-07-21                            BER(3)
Impressum