|
NAMEEncoding::BER - Perl module for encoding/decoding data using ASN.1 Basic Encoding Rules (BER)SYNOPSISuse Encoding::BER; my $enc = Encoding::BER->new(); my $ber = $enc->encode( $data ); my $xyz = $enc->decode( $ber ); DESCRIPTIONUnlike many other BER encoder/decoders, this module uses tree structured data as the interface to/from the encoder/decoder.The decoder does not require any form of template or description of the data to be decoded. Given arbitrary BER encoded data, the decoder produces a tree shaped perl data structure from it. The encoder takes a perl data structure and produces a BER encoding from it. METHODS
ENCODING DATAYou can give data to the encoder in either of two ways (or mix and match).You can specify simple values directly, and the module will guess the correct tags to use. Things that look like integers will be encoded as "integer", things that look like floating-point numbers will be encoded as "real", things that look like strings, will be encoded as "octet_string". Arrayrefs will be encoded as "sequence". example: $enc->encode( [0, 1.2, "foobar", [ "baz", 37.94 ]] ); Alternatively, you can explicity specify the type using a hashref containing "type" and "value" keys. example: $enc->encode( { type => 'sequence', value => [ { type => 'integer', value => 37 } ] } ); The type may be specfied as either a string containg the tag-name, or as an arryref containing the class, type, and tag-name. example: type => 'octet_string' type => ['universal', 'primitive', 'octet_string'] Note: using the second form above, you can create wacky encodings that no one will be able to decode. The value should be a scalar value for primitive types, and an arrayref for constructed types. example: { type => 'octet_string', value => 'foobar' } { type => 'set', value => [ 1, 2, 3 ] } { type => ['universal', 'constructed', 'octet_string'], value => [ 'foo', 'bar' ] } DECODED DATAThe values returned from decoding will be similar to the way data to be encoded is specified, in the full long form. Additionally, the hashref will contain: "identval" the numeric value representing the class+type+tag and "tagnum" the numeric tag number.example: a string might be returned as: { type => ['universal', 'primitive', 'octet_string'], identval => 4, tagnum => 4, value => 'foobar', } TAG NAMESThe following are recognized as valid names of tags:bit_string bmp_string bool boolean character_string embedded_pdv enum enumerated external float general_string generalized_time graphic_string ia5_string int int32 integer integer32 iso646_string null numeric_string object_descriptor object_identifier octet_string oid printable_string real relative_object_identifier relative_oid roid sequence sequence_of set set_of string t61_string teletex_string uint uint32 universal_string universal_time unsigned_int unsigned_int32 unsigned_integer utf8_string videotex_string visible_string Math::BigIntIf you have Math::BigInt, it can be used for large integers. If you want it used, you must load it yourself:use Math::BigInt; use Encoding::BER; It can be used for both encoding and decoding. The encoder can be handed either a Math::BigInt object, or a "big string of digits" marked as an integer: use math::BigInt; my $x = Math::BigInt->new( '12345678901234567890' ); $enc->encode( $x ) $enc->encode( { type => 'integer', '12345678901234567890' } ); During decoding, a Math::BigInt object will be created if the value "looks big". EXPORTSBy default, this module exports nothing. This can be overridden by specifying something else:use Encoding::BER ('import', 'hexdump'); LIMITATIONSIf your application uses the same tag-number for more than one type of implicitly tagged primitive, the decoder will not be able to distinguish between them, and will not be able to decode them both correctly. eg:width ::= [context 12] implicit integer girth ::= [context 12] implicit real If you specify data to be encoded using the "short form", the module may guess the type differently than you expect. If it matters, be explicit. This module does not do data validation. It will happily let you encode a non-ascii string as a "ia5_string", etc. PREREQUISITESIf you wish to use "real"s, the POSIX module is required. It will be loaded automatically, if needed.Familiarity with ASN.1 and BER encoding is probably required to take advantage of this module. SEE ALSOYellowstone National Park Encoding::BER::CER, Encoding::BER::DER Encoding::BER::SNMP, Encoding::BER::Dumper ITU-T x.690 AUTHORJeff Weisberg - http://www.tcp4me.com
Visit the GSP FreeBSD Man Page Interface. |