… | |
… | |
28 | [ ASN_APPLICATION, ASN_TIMETICKS, 0, 1817903850 ], # SNMP TimeTicks |
28 | [ ASN_APPLICATION, ASN_TIMETICKS, 0, 1817903850 ], # SNMP TimeTicks |
29 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # the varbindlist |
29 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # the varbindlist |
30 | [ |
30 | [ |
31 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # a single varbind, "key value" pair |
31 | [ ASN_UNIVERSAL, ASN_SEQUENCE, 1, # a single varbind, "key value" pair |
32 | [ |
32 | [ |
33 | [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.1.1.8.1.2.1" ], # the oid |
33 | [ ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, 0, "1.3.6.1.4.1.9.9.215.1.1.8.1.2.1" ], |
34 | [ ASN_UNIVERSAL, ASN_OCTET_STRING, 0, "...data..." # the value |
34 | [ ASN_UNIVERSAL, ASN_OCTET_STRING, 0, "...data..." # the value |
35 | ] |
35 | ] |
36 | ] |
36 | ] |
37 | ], |
37 | ], |
38 | ... |
38 | ... |
… | |
… | |
82 | data structures. It supports various mappings to JSON, XML, but most |
82 | data structures. It supports various mappings to JSON, XML, but most |
83 | importantly, to a various binary encodings such as BER, that is the topic |
83 | importantly, to a various binary encodings such as BER, that is the topic |
84 | of this module, and is used in SNMP or LDAP for example. |
84 | of this module, and is used in SNMP or LDAP for example. |
85 | |
85 | |
86 | While ASN.1 defines a schema that is useful to interpret encoded data, |
86 | While ASN.1 defines a schema that is useful to interpret encoded data, |
87 | the BER encoding is actually somehat self-describing: you might not know |
87 | the BER encoding is actually somewhat self-describing: you might not know |
88 | whether something is a string or a number or a sequence or something else, |
88 | whether something is a string or a number or a sequence or something else, |
89 | but you can nevertheless decode the overall structure, even if you end up |
89 | but you can nevertheless decode the overall structure, even if you end up |
90 | with just a binary blob for the actual value. |
90 | with just a binary blob for the actual value. |
91 | |
91 | |
92 | This works because BER values are tagged with a type and a namespace, |
92 | This works because BER values are tagged with a type and a namespace, |
… | |
… | |
120 | I<DATA> member, and you may re-assign the array itself, e.g.: |
120 | I<DATA> member, and you may re-assign the array itself, e.g.: |
121 | |
121 | |
122 | $ber = ber_decode $binbuf; |
122 | $ber = ber_decode $binbuf; |
123 | |
123 | |
124 | # the following is NOT legal: |
124 | # the following is NOT legal: |
125 | $ber->[BER_CLASS] = ASN_PRIVATE; # ERROR, readonly(!) |
125 | $ber->[BER_CLASS] = ASN_PRIVATE; # ERROR, CLASS/TAG/CONSTRUCTED are READ ONLY(!) |
126 | |
126 | |
127 | # but all of the following are fine: |
127 | # but all of the following are fine: |
128 | $ber->[BER_DATA] = "string"; |
128 | $ber->[BER_DATA] = "string"; |
129 | $ber->[BER_DATA] = [ASN_UNIVERSAL, ASN_INTEGER32, 0, 123]; |
129 | $ber->[BER_DATA] = [ASN_UNIVERSAL, ASN_INTEGER32, 0, 123]; |
130 | @$ber = (ASN_APPLICATION, SNMP_TIMETICKS, 1000); |
130 | @$ber = (ASN_APPLICATION, SNMP_TIMETICKS, 0, 1000); |
131 | |
131 | |
132 | I<CLASS> is something like a namespace for I<TAG>s - there is the |
132 | I<CLASS> is something like a namespace for I<TAG>s - there is the |
133 | C<ASN_UNIVERSAL> namespace which defines tags common to all ASN.1 |
133 | C<ASN_UNIVERSAL> namespace which defines tags common to all ASN.1 |
134 | implementations, the C<ASN_APPLICATION> namespace which defines tags for |
134 | implementations, the C<ASN_APPLICATION> namespace which defines tags for |
135 | specific applications (for example, the SNMP C<Unsigned32> type is in this |
135 | specific applications (for example, the SNMP C<Unsigned32> type is in this |
… | |
… | |
249 | true. |
249 | true. |
250 | |
250 | |
251 | =item $bool = ber_is_oid $tuple, $oid_string |
251 | =item $bool = ber_is_oid $tuple, $oid_string |
252 | |
252 | |
253 | Returns true if the C<$tuple> represents an ASN_OBJECT_IDENTIFIER |
253 | Returns true if the C<$tuple> represents an ASN_OBJECT_IDENTIFIER |
254 | that exactly matches C$oid_string>. Exmaple: |
254 | that exactly matches C<$oid_string>. Example: |
255 | |
255 | |
256 | ber_is_oid $tuple, "1.3.6.1.4" |
256 | ber_is_oid $tuple, "1.3.6.1.4" |
257 | or die "oid must be 1.3.6.1.4"; |
257 | or die "oid must be 1.3.6.1.4"; |
258 | |
258 | |
259 | =item $oid = ber_is_oid $tuple |
259 | =item $oid = ber_is_oid $tuple |