--- Convert-BER-XS/XS.pm 2019/04/20 14:59:26 1.24 +++ Convert-BER-XS/XS.pm 2019/04/20 15:23:26 1.25 @@ -19,14 +19,14 @@ [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, [ - [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 0 ], # snmp version 1 + [ ASN_UNIVERSAL, ASN_INTEGER, 0, 0 ], # snmp version 1 [ ASN_UNIVERSAL, 4, 0, "public" ], # community [ ASN_CONTEXT, 4, 1, # CHOICE, constructed - trap PDU [ [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.2" ], # enterprise oid [ ASN_APPLICATION, SNMP_IPADDRESS, 0, "10.0.0.1" ], # SNMP IpAddress - [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 6 ], # generic trap - [ ASN_UNIVERSAL, ASN_INTEGER32, 0, 1 ], # specific trap + [ ASN_UNIVERSAL, ASN_INTEGER, 0, 6 ], # generic trap + [ ASN_UNIVERSAL, ASN_INTEGER, 0, 1 ], # specific trap [ ASN_APPLICATION, SNMP_TIMETICKS, 0, 1817903850 ], # SNMP TimeTicks [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # the varbindlist [ @@ -44,7 +44,7 @@ my $msg = ber_is_seq $ber or die "SNMP message does not start with a sequence"; - ber_is $msg->[0], ASN_UNIVERSAL, ASN_INTEGER32, 0 + ber_is $msg->[0], ASN_UNIVERSAL, ASN_INTEGER, 0 or die "SNMP message does not start with snmp version\n"; # message is SNMP v1 or v2c? @@ -57,8 +57,8 @@ # 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_i32 $trap->[2], 6) - and (ber_is_i32 $trap->[3], 1) # mac changed msg + and (ber_is_int $trap->[2], 6) + and (ber_is_int $trap->[3], 1) # mac changed msg ) { ... and so on @@ -115,7 +115,7 @@ ASN tag values (some of which are aliases, such as C). Their numerical value corresponds exactly to the numbers used in BER/X.690. - ASN_BOOLEAN ASN_INTEGER32 ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OBJECT_IDENTIFIER + ASN_BOOLEAN ASN_INTEGER ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OBJECT_IDENTIFIER ASN_OBJECT_DESCRIPTOR ASN_OID 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 @@ -142,13 +142,13 @@ C and the match helper functions: - ber_decode ber_is ber_is_seq ber_is_i32 ber_is_oid + ber_decode ber_is ber_is_seq ber_is_int ber_is_oid =item C<:encode> C and the construction helper functions: - ber_encode ber_i32 + ber_encode ber_int =back @@ -169,8 +169,8 @@ 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 32 bit signed integers and 16(!) different +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 @@ -188,7 +188,7 @@ For example: - [ASN_UNIVERSAL, ASN_INTEGER32, 0, 177] # the integer 177 + [ASN_UNIVERSAL, ASN_INTEGER, 0, 177] # the integer 177 [ASN_UNIVERSAL, ASN_OCTET_STRING, 0, "john"] # the string "john" [ASN_UNIVERSAL, ASN_OID, 0, "1.3.6.133"] # some OID [ASN_UNIVERSAL, ASN_SEQUENCE, 1, [ [ASN_UNIVERSAL... # a sequence @@ -209,7 +209,7 @@ # but all of the following are fine: $ber->[BER_DATA] = "string"; - $ber->[BER_DATA] = [ASN_UNIVERSAL, ASN_INTEGER32, 0, 123]; + $ber->[BER_DATA] = [ASN_UNIVERSAL, ASN_INTEGER, 0, 123]; @$ber = (ASN_APPLICATION, SNMP_TIMETICKS, 0, 1000); I is something like a namespace for Is - there is the @@ -225,7 +225,7 @@ of these, you need to tell this module how to handle those via profiles. The most common tags in the C namespace are -C, C, C, C, +C, C, C, C, C, C, C and C. @@ -268,6 +268,15 @@ C<$Convert::BER::XS::SNMP_PROFILE> that knows about the additional SNMP types. +Example: decode a BER blob using the default profile - SNMP values will be +decided as raw strings. + + $tuple = ber_decode $data; + +Example: as above, but use the provided SNMP profile. + + $tuple = ber_encode $data, $Convert::BER::XS::SNMP_PROFILE; + =item $bindata = ber_encode $tuple[, $profile] Encodes the BER tuple into a BER/DER data structure. AS with @@ -308,7 +317,7 @@ ber_is $tuple, ASN_UNIVERSAL, ASN_NULL or die "tuple is not an ASN NULL value"; - ber_is $tuple, ASN_UNIVERSAL, ASN_INTEGER32, 0, 50 + ber_is $tuple, ASN_UNIVERSAL, ASN_INTEGER, 0, 50 or die "BER integer must be 50"; =item $seq = ber_is_seq $tuple @@ -325,19 +334,19 @@ # now we know $snmp is a sequence, so decode the SNMP version - my $version = ber_is_i32 $snmp->[0] + my $version = ber_is_int $snmp->[0] or die "SNMP packet invalid: does not start with version number"; -=item $bool = ber_is_i32 $tuple, $i32 +=item $bool = ber_is_int $tuple, $int -Returns a true value if the C<$tuple> represents an ASN INTEGER32 with -the value C<$i32>. +Returns a true value if the C<$tuple> represents an ASN INTEGER with +the value C<$int>. -=item $i32 = ber_is_i32 $tuple +=item $int = ber_is_int $tuple -Returns true (and extracts the integer value) if the C<$tuple> is an ASN -INTEGER32. For C<0>, this function returns a special value that is 0 but -true. +Returns true (and extracts the integer value) if the C<$tuple> is an +C. For C<0>, this function returns a special value that is 0 +but true. =item $bool = ber_is_oid $tuple, $oid_string @@ -358,9 +367,9 @@ =over -=item $tuple = ber_i32 $value +=item $tuple = ber_int $value -Constructs a new C tuple. +Constructs a new C tuple. =back @@ -392,7 +401,7 @@ BER_CLASS BER_TAG BER_CONSTRUCTED BER_DATA )], const_asn => [qw( - ASN_BOOLEAN ASN_INTEGER32 ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OBJECT_IDENTIFIER + ASN_BOOLEAN ASN_INTEGER ASN_BIT_STRING ASN_OCTET_STRING ASN_NULL ASN_OBJECT_IDENTIFIER ASN_OBJECT_DESCRIPTOR ASN_OID 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 @@ -411,11 +420,11 @@ )], decode => [qw( ber_decode - ber_is ber_is_seq ber_is_i32 ber_is_oid + ber_is ber_is_seq ber_is_int ber_is_oid )], encode => [qw( ber_encode - ber_i32 + ber_int )], ); @@ -596,7 +605,7 @@ only when your perl supports those. This module does not generally care about ranges, i.e. it will happily -de-/encode 64 bit integers into an C value, or a negative +de-/encode 64 bit integers into an C value, or a negative number into an C. OBJECT IDENTIFIEERs cannot have unlimited length, although the limit is