… | |
… | |
58 | ASN_CLASS_SHIFT = 6, |
58 | ASN_CLASS_SHIFT = 6, |
59 | |
59 | |
60 | // ASN_APPLICATION SNMP |
60 | // ASN_APPLICATION SNMP |
61 | SNMP_IPADDRESS = 0x00, |
61 | SNMP_IPADDRESS = 0x00, |
62 | SNMP_COUNTER32 = 0x01, |
62 | SNMP_COUNTER32 = 0x01, |
|
|
63 | SNMP_GAUGE32 = 0x02, |
63 | SNMP_UNSIGNED32 = 0x02, |
64 | SNMP_UNSIGNED32 = 0x02, |
64 | SNMP_TIMETICKS = 0x03, |
65 | SNMP_TIMETICKS = 0x03, |
65 | SNMP_OPAQUE = 0x04, |
66 | SNMP_OPAQUE = 0x04, |
66 | SNMP_COUNTER64 = 0x06, |
67 | SNMP_COUNTER64 = 0x06, |
67 | }; |
68 | }; |
… | |
… | |
259 | if (expect_false (c == 0x80)) |
260 | if (expect_false (c == 0x80)) |
260 | error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)"); |
261 | error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)"); |
261 | |
262 | |
262 | for (;;) |
263 | for (;;) |
263 | { |
264 | { |
|
|
265 | if (expect_false (res >> UVSIZE * 8 - 7)) |
|
|
266 | error ("BER variable integer overflow"); |
|
|
267 | |
264 | res = (res << 7) | (c & 0x7f); |
268 | res = (res << 7) | (c & 0x7f); |
265 | |
269 | |
266 | if (!(c & 0x80)) |
270 | if (!(c & 0x80)) |
267 | return res; |
271 | return res; |
268 | |
272 | |
… | |
… | |
325 | |
329 | |
326 | int negative = data [0] & 0x80; |
330 | int negative = data [0] & 0x80; |
327 | |
331 | |
328 | UV val = negative ? -1 : 0; // copy signbit to all bits |
332 | UV val = negative ? -1 : 0; // copy signbit to all bits |
329 | |
333 | |
|
|
334 | if (len > UVSIZE + (!negative && !*data)) |
|
|
335 | error ("INTEGER overflow"); |
|
|
336 | |
330 | do |
337 | do |
331 | val = (val << 8) | *data++; |
338 | val = (val << 8) | *data++; |
332 | while (--len); |
339 | while (--len); |
333 | |
340 | |
334 | // the cast to IV relies on implementation-defined behaviour (two's complement cast) |
341 | // the cast to IV relies on implementation-defined behaviour (two's complement cast) |
… | |
… | |
388 | } |
395 | } |
389 | |
396 | |
390 | U8 *end = cur + len; |
397 | U8 *end = cur + len; |
391 | UV w = get_w (); |
398 | UV w = get_w (); |
392 | |
399 | |
393 | static char oid[MAX_OID_STRLEN]; // static, becaueds too large for stack |
400 | static char oid[MAX_OID_STRLEN]; // static, because too large for stack |
394 | char *app = oid; |
401 | char *app = oid; |
395 | |
402 | |
396 | if (relative) |
403 | if (relative) |
397 | app = write_uv (app, w); |
404 | app = write_uv (app, w); |
398 | else if (w < 2 * 40) |
405 | else if (w < 2 * 40) |
… | |
… | |
1069 | const_iv (BER_TYPE_IPADDRESS) |
1076 | const_iv (BER_TYPE_IPADDRESS) |
1070 | const_iv (BER_TYPE_CROAK) |
1077 | const_iv (BER_TYPE_CROAK) |
1071 | |
1078 | |
1072 | const_iv (SNMP_IPADDRESS) |
1079 | const_iv (SNMP_IPADDRESS) |
1073 | const_iv (SNMP_COUNTER32) |
1080 | const_iv (SNMP_COUNTER32) |
|
|
1081 | const_iv (SNMP_GAUGE32) |
1074 | const_iv (SNMP_UNSIGNED32) |
1082 | const_iv (SNMP_UNSIGNED32) |
1075 | const_iv (SNMP_TIMETICKS) |
1083 | const_iv (SNMP_TIMETICKS) |
1076 | const_iv (SNMP_OPAQUE) |
1084 | const_iv (SNMP_OPAQUE) |
1077 | const_iv (SNMP_COUNTER64) |
1085 | const_iv (SNMP_COUNTER64) |
1078 | }; |
1086 | }; |
1079 | |
1087 | |
1080 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
1088 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
1081 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
1089 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
1082 | } |
1090 | } |
1083 | |
1091 | |
1084 | SV * |
1092 | void |
1085 | ber_decode (SV *ber, SV *profile = &PL_sv_undef) |
1093 | ber_decode (SV *ber, SV *profile = &PL_sv_undef) |
|
|
1094 | ALIAS: |
|
|
1095 | ber_decode_prefix = 1 |
1086 | CODE: |
1096 | PPCODE: |
1087 | { |
1097 | { |
1088 | cur_profile = SvPROFILE (profile); |
1098 | cur_profile = SvPROFILE (profile); |
1089 | STRLEN len; |
1099 | STRLEN len; |
1090 | buf = (U8 *)SvPVbyte (ber, len); |
1100 | buf = (U8 *)SvPVbyte (ber, len); |
1091 | cur = buf; |
1101 | cur = buf; |
1092 | end = buf + len; |
1102 | end = buf + len; |
1093 | |
1103 | |
1094 | RETVAL = decode_ber (); |
1104 | SV *tuple = decode_ber (); |
|
|
1105 | |
|
|
1106 | EXTEND (SP, 2); |
|
|
1107 | PUSHs (sv_2mortal (tuple)); |
|
|
1108 | |
|
|
1109 | if (ix) |
|
|
1110 | PUSHs (sv_2mortal (newSViv (cur - buf))); |
|
|
1111 | else if (cur != end) |
|
|
1112 | error ("trailing garbage after BER data"); |
1095 | } |
1113 | } |
1096 | OUTPUT: RETVAL |
|
|
1097 | |
1114 | |
1098 | void |
1115 | void |
1099 | ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef) |
1116 | ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef) |
1100 | PPCODE: |
1117 | PPCODE: |
1101 | { |
1118 | { |