Convert-BER-XS

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

           my $trap = $msg->[2][BER_DATA];

           # check whether trap is a cisco mac notification mac changed message
           if (
              (ber_is_oid $trap->[0], "1.3.6.1.4.1.9.9.215.2") # cmnInterfaceObjects
              and (ber_is_int $trap->[2], 6)
              and (ber_is_int $trap->[3], 1) # mac changed msg
           ) {
              ... and so on

     # finally, let's encode it again and hope it results in the same bit pattern

     my $buf = ber_encode $ber, $Convert::BER::XS::SNMP_PROFILE;

DESCRIPTION
    WARNING: Before release 1.0, the API is not considered stable in any
    way.

    This module implements a *very* low level BER/DER en-/decoder.

    It is tuned for low memory and high speed, while still maintaining some
    level of user-friendlyness.

  EXPORT TAGS AND CONSTANTS
    By default this module doesn't export any symbols, but if you don't want
    to break your keyboard, editor or eyesight with extremely long names, I
    recommend importing the ":all" tag. Still, you can selectively import
    things.

    ":all"
        All of the below. Really. Recommended for at least first steps, or
        if you don't care about a few kilobytes of wasted memory (and
        namespace).

    ":const"
        All of the strictly ASN.1-related constants defined by this module,
        the same as ":const_asn :const_index". Notably, this does not
        contain ":const_ber_type" and ":const_snmp".

        A good set to get everything you need to decode and match BER data
        would be ":decode :const".

    ":const_index"
        The BER tuple array index constants:

                BER_CLASS BER_TAG BER_FLAGS BER_DATA

    ":const_asn"
        ASN class values (these are 0, 1, 2 and 3, respectively - exactly
        the two topmost bits from the identifier octet shifted 6 bits to the
        right):

              ASN_UNIVERSAL ASN_APPLICATION ASN_CONTEXT ASN_PRIVATE

        ASN tag values (some of which are aliases, such as "ASN_OID"). Their
        numerical value corresponds exactly to the numbers used in
        BER/X.690.

              ASN_BOOLEAN ASN_INTEGER ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OID
              ASN_OBJECT_IDENTIFIER ASN_OBJECT_DESCRIPTOR ASN_EXTERNAL ASN_REAL ASN_SEQUENCE ASN_ENUMERATED
              ASN_EMBEDDED_PDV ASN_UTF8_STRING ASN_RELATIVE_OID ASN_SET ASN_NUMERIC_STRING
              ASN_PRINTABLE_STRING ASN_TELETEX_STRING ASN_T61_STRING ASN_VIDEOTEX_STRING ASN_IA5_STRING
              ASN_ASCII_STRING ASN_UTC_TIME ASN_GENERALIZED_TIME ASN_GRAPHIC_STRING ASN_VISIBLE_STRING
              ASN_ISO646_STRING ASN_GENERAL_STRING ASN_UNIVERSAL_STRING ASN_CHARACTER_STRING ASN_BMP_STRING

    ":const_ber_type"
        The BER type constants, explained in the PROFILES section.

              BER_TYPE_BYTES BER_TYPE_UTF8 BER_TYPE_UCS2 BER_TYPE_UCS4 BER_TYPE_INT
              BER_TYPE_OID BER_TYPE_RELOID BER_TYPE_NULL BER_TYPE_BOOL BER_TYPE_REAL
              BER_TYPE_IPADDRESS BER_TYPE_CROAK

    ":const_snmp"
        Constants only relevant to SNMP. These are the tag values used by
        SNMP in the "ASN_APPLICATION" namespace and have the exact numerical
        value as in BER/RFC 2578.

              SNMP_IPADDRESS SNMP_COUNTER32 SNMP_UNSIGNED32 SNMP_GAUGE32
              SNMP_TIMETICKS SNMP_OPAQUE SNMP_COUNTER64

    ":decode"
        "ber_decode" and the match helper functions:

              ber_decode ber-decode_prefix
              ber_is ber_is_seq ber_is_int ber_is_oid
              ber_dump

    ":encode"
        "ber_encode" and the construction helper functions:

              ber_encode
              ber_int

  ASN.1/BER/DER/... BASICS
    ASN.1 is a strange language that can be used to describe protocols and
    data structures. It supports various mappings to JSON, XML, but most
    importantly, to a various binary encodings such as BER, that is the
    topic of this module, and is used in SNMP, LDAP or X.509 for example.

    While ASN.1 defines a schema that is useful to interpret encoded data,
    the BER encoding is actually somewhat self-describing: you might not
    know whether something is a string or a number or a sequence or
    something else, but you can nevertheless decode the overall structure,
    even if you end up with just a binary blob for the actual value.

    This works because BER values are tagged with a type and a namespace,
    and also have a flag that says whether a value consists of subvalues (is
    "constructed") or not (is "primitive").

    Tags are simple integers, and ASN.1 defines a somewhat weird assortment
    of those - for example, you have one integers and 16(!) different string
    types, but there is no Unsigned32 type for example. Different
    applications work around this in different ways, for example, SNMP
    defines application-specific Gauge32, Counter32 and Unsigned32, which
    are mapped to two different tags: you can distinguish between Counter32
    and the others, but not between Gause32 and Unsigned32, without the
    ASN.1 schema.

    Ugh.

  DECODED BER REPRESENTATION



( run in 1.689 second using v1.01-cache-2.11-cpan-71847e10f99 )