Convert-BER-XS

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    This works by mapping specific class/tag combinations to an internal
    "ber type".

    The default profile supports the standard ASN.1 types, but no
    application-specific ones. This means that class/tag combinations not in
    the base set of ASN.1 are decoded into their raw octet strings.

    "Convert::BER::XS" defines two profile variables you can use out of the
    box:

    $Convert::BER::XS::DEFAULT_PROFILE
        This is the default profile, i.e. the profile that is used when no
        profile is specified for de-/encoding.

        You can modify it, but remember that this modifies the defaults for
        all callers that rely on the default profile.

    $Convert::BER::XS::SNMP_PROFILE
        A profile with mappings for SNMP-specific application tags added.
        This is useful when de-/encoding SNMP data.

        Example:

           $ber = ber_decode $data, $Convert::BER::XS::SNMP_PROFILE;

  The Convert::BER::XS::Profile class
    $profile = new Convert::BER::XS::Profile
        Create a new profile. The profile will be identical to the default
        profile.

    $profile->set ($class, $tag, $type)
        Sets the mapping for the given $class/$tag combination to $type,
        which must be one of the "BER_TYPE_*" constants.

        Note that currently, the mapping is stored in a flat array, so large
        values of $tag will consume large amounts of memory.

        Example:

           $profile = new Convert::BER::XS::Profile;
           $profile->set (ASN_APPLICATION, SNMP_COUNTER32, BER_TYPE_INT);
           $ber = ber_decode $data, $profile;

    $type = $profile->get ($class, $tag)
        Returns the BER type mapped to the given $class/$tag combination.

  BER Types
    This lists the predefined BER types. BER types are formatters used
    internally to format and encode BER values. You can assign any
    "BER_TYPE" to any "CLASS"/"TAG" combination tgo change how that tag is
    decoded or encoded.

    "BER_TYPE_BYTES"
        The raw octets of the value. This is the default type for unknown
        tags and de-/encodes the value as if it were an octet string, i.e.
        by copying the raw bytes.

    "BER_TYPE_UTF8"
        Like "BER_TYPE_BYTES", but decodes the value as if it were a UTF-8
        string (without validation!) and encodes a perl unicode string into
        a UTF-8 BER string.

    "BER_TYPE_UCS2"
        Similar to "BER_TYPE_UTF8", but treats the BER value as UCS-2
        encoded string.

    "BER_TYPE_UCS4"
        Similar to "BER_TYPE_UTF8", but treats the BER value as UCS-4
        encoded string.

    "BER_TYPE_INT"
        Encodes and decodes a BER integer value to a perl integer scalar.
        This should correctly handle 64 bit signed and unsigned values.

    "BER_TYPE_OID"
        Encodes and decodes an OBJECT IDENTIFIER into dotted form without
        leading dot, e.g. 1.3.6.1.213.

    "BER_TYPE_RELOID"
        Same as "BER_TYPE_OID" but uses relative object identifier encoding:
        ASN.1 has this hack of encoding the first two OID components into a
        single integer in a weird attempt to save an insignificant amount of
        space in an otherwise wasteful encoding, and relative OIDs are
        basically OIDs without this hack. The practical difference is that
        the second component of an OID can only have the values 1..40, while
        relative OIDs do not have this restriction.

    "BER_TYPE_NULL"
        Decodes an "ASN_NULL" value into "undef", and always encodes a
        "ASN_NULL" type, regardless of the perl value.

    "BER_TYPE_BOOL"
        Decodes an "ASN_BOOLEAN" value into 0 or 1, and encodes a perl
        boolean value into an "ASN_BOOLEAN".

    "BER_TYPE_REAL"
        Decodes/encodes a BER real value. NOT IMPLEMENTED.

    "BER_TYPE_IPADDRESS"
        Decodes/encodes a four byte string into an IPv4 dotted-quad address
        string in Perl. Given the obsolete nature of this type, this is a
        low-effort implementation that simply uses "sprintf" and
        "sscanf"-style conversion, so it won't handle all string forms
        supported by "inet_aton" for example.

    "BER_TYPE_CROAK"
        Always croaks when encountered during encoding or decoding - the
        default behaviour when encountering an unknown type is to treat it
        as "BER_TYPE_BYTES". When you don't want that but instead prefer a
        hard error for some types, then "BER_TYPE_CROAK" is for you.

  Example Profile
    The following creates a profile suitable for SNMP - it's exactly
    identical to the $Convert::BER::XS::SNMP_PROFILE profile.

       our $SNMP_PROFILE = new Convert::BER::XS::Profile;

       $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_IPADDRESS , BER_TYPE_IPADDRESS);
       $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_COUNTER32 , BER_TYPE_INT);
       $SNMP_PROFILE->set (ASN_APPLICATION, SNMP_UNSIGNED32, BER_TYPE_INT);



( run in 1.105 second using v1.01-cache-2.11-cpan-39bf76dae61 )