BER(3pm) | User Contributed Perl Documentation | BER(3pm) |
BER - Basic Encoding Rules (BER) of Abstract Syntax Notation One (ASN.1)
use BER; $encoded = encode_sequence (encode_int (123), encode_string ("foo")); ($i, $s) = decode_by_template ($encoded, "%{%i%s"); # $i will now be 123, $s the string "foo".
This is a simple library to encode and decode data using the Basic Encoding Rules (BER) of Abstract Syntax Notation One (ASN.1). It does not claim to be a complete implementation of the standard, but implements enough of the BER standard to encode and decode SNMP messages.
If non-zero (the default), "pretty_print" will convert TimeTicks to "human readable" strings containing days, hours, minutes and seconds.
If the variable is zero, "pretty_print" will simply return an unsigned integer representing hundredths of seconds. If you prefer this, bind $pretty_print_timeticks to zero.
When they encounter errors, the routines in this module will generally return "undef") and leave an informative error message in $errmsg).
This is functionally identical to encode_int(0).
$encoded = encode_oid (1,3,6,1,...);
This is used e.g. in binding lists for variables that don't have a value (yet)
$encoded = encode_sequence (encoded1, encoded2, ...); $encoded = encode_tagged_sequence (tag, encoded1, encoded2, ...);
Take already encoded values, and extend them to an encoded sequence. "encoded_sequence" uses the generic sequence tag, while with "encode_tagged_sequence" you can specify your own tag.
This can either be passed as a four-octet sequence in network byte order, or as a text string in dotted-quad notation, e.g. "192.0.2.234".
The integer should count hundredths of a second since the epoch defined by "sysUpTime.0".
This function can be extended by registering pretty-printing methods for specific type codes. Most BER type codes used in SNMP already have such methods pre-registered by default. See "register_pretty_printer" for how new methods can be added.
($var1, ...) = decode_by_template ($pdu, $template, ...);
The template can contain various %X directives. Some directives consume additional arguments following the template itself. Most directives will cause values to be returned. The values are returned as a sequence in the order of the directives that generated them.
($first, $rest) = decode_sequence ($pdu);
Checks whether the PDU has a sequence type tag and a plausible length field. Splits the initial element off the list, and returns both this and the remainder of the PDU.
This function takes a hashref that specifies functions to call when the specified value type is being printed. It returns the number of functions that were registered.
Created by: Simon Leinen <simon.leinen@switch.ch>
Contributions and fixes by:
Copyright (c) 1995-2009, Simon Leinen.
This program is free software; you can redistribute it under the "Artistic License 2.0" included in this distribution (file "Artistic").
2022-11-26 | perl v5.36.0 |