… | |
… | |
65 | SNMP_TIMETICKS = 0x03, |
65 | SNMP_TIMETICKS = 0x03, |
66 | SNMP_OPAQUE = 0x04, |
66 | SNMP_OPAQUE = 0x04, |
67 | SNMP_COUNTER64 = 0x06, |
67 | SNMP_COUNTER64 = 0x06, |
68 | }; |
68 | }; |
69 | |
69 | |
|
|
70 | // tlow-level types this module can ecode the above (and more) into |
70 | enum { |
71 | enum { |
71 | BER_TYPE_BYTES, |
72 | BER_TYPE_BYTES, |
72 | BER_TYPE_UTF8, |
73 | BER_TYPE_UTF8, |
73 | BER_TYPE_UCS2, |
74 | BER_TYPE_UCS2, |
74 | BER_TYPE_UCS4, |
75 | BER_TYPE_UCS4, |
… | |
… | |
80 | BER_TYPE_REAL, |
81 | BER_TYPE_REAL, |
81 | BER_TYPE_IPADDRESS, |
82 | BER_TYPE_IPADDRESS, |
82 | BER_TYPE_CROAK, |
83 | BER_TYPE_CROAK, |
83 | }; |
84 | }; |
84 | |
85 | |
|
|
86 | // tuple array indices |
85 | enum { |
87 | enum { |
86 | BER_CLASS = 0, |
88 | BER_CLASS = 0, |
87 | BER_TAG = 1, |
89 | BER_TAG = 1, |
88 | BER_FLAGS = 2, |
90 | BER_FLAGS = 2, |
89 | BER_DATA = 3, |
91 | BER_DATA = 3, |
… | |
… | |
141 | { |
143 | { |
142 | if (!SvOK (profile)) |
144 | if (!SvOK (profile)) |
143 | return default_profile; |
145 | return default_profile; |
144 | |
146 | |
145 | if (!SvROK (profile)) |
147 | if (!SvROK (profile)) |
146 | croak ("invalid profile"); |
148 | croak ("Convert::BER::XS::Profile expected"); |
147 | |
149 | |
148 | profile = SvRV (profile); |
150 | profile = SvRV (profile); |
149 | |
151 | |
150 | if (SvSTASH (profile) != profile_stash) |
152 | if (SvSTASH (profile) != profile_stash) |
151 | croak ("invalid profile object"); |
153 | croak ("Convert::BER::XS::Profile expected"); |
152 | |
154 | |
153 | return (void *)profile; |
155 | return (void *)profile; |
154 | } |
156 | } |
155 | |
157 | |
156 | static int |
158 | static int |
… | |
… | |
228 | } |
230 | } |
229 | |
231 | |
230 | // get_* functions fetch something from the buffer |
232 | // get_* functions fetch something from the buffer |
231 | // decode_* functions use get_* fun ctions to decode ber values |
233 | // decode_* functions use get_* fun ctions to decode ber values |
232 | |
234 | |
|
|
235 | // get single octet |
|
|
236 | static U8 |
|
|
237 | get_u8 (void) |
|
|
238 | { |
|
|
239 | if (cur == end) |
|
|
240 | error ("unexpected end of message buffer"); |
|
|
241 | |
|
|
242 | return *cur++; |
|
|
243 | } |
|
|
244 | |
233 | // get n octets |
245 | // get n octets |
234 | static U8 * |
246 | static U8 * |
235 | get_n (UV count) |
247 | get_n (UV count) |
236 | { |
248 | { |
237 | want (count); |
249 | want (count); |
238 | U8 *res = cur; |
250 | U8 *res = cur; |
239 | cur += count; |
251 | cur += count; |
240 | return res; |
252 | return res; |
241 | } |
253 | } |
242 | |
254 | |
243 | // get single octet |
|
|
244 | static U8 |
|
|
245 | get_u8 (void) |
|
|
246 | { |
|
|
247 | if (cur == end) |
|
|
248 | error ("unexpected end of message buffer"); |
|
|
249 | |
|
|
250 | return *cur++; |
|
|
251 | } |
|
|
252 | |
|
|
253 | // get ber-encoded integer (i.e. pack "w") |
255 | // get ber-encoded integer (i.e. pack "w") |
254 | static UV |
256 | static UV |
255 | get_w (void) |
257 | get_w (void) |
256 | { |
258 | { |
257 | UV res = 0; |
259 | UV res = 0; |
… | |
… | |
261 | error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)"); |
263 | error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)"); |
262 | |
264 | |
263 | for (;;) |
265 | for (;;) |
264 | { |
266 | { |
265 | if (expect_false (res >> UVSIZE * 8 - 7)) |
267 | if (expect_false (res >> UVSIZE * 8 - 7)) |
266 | error ("BER variable integer overflow"); |
268 | error ("BER variable length integer overflow"); |
267 | |
269 | |
268 | res = (res << 7) | (c & 0x7f); |
270 | res = (res << 7) | (c & 0x7f); |
269 | |
271 | |
270 | if (!(c & 0x80)) |
272 | if (expect_true (!(c & 0x80))) |
271 | return res; |
273 | return res; |
272 | |
274 | |
273 | c = get_u8 (); |
275 | c = get_u8 (); |
274 | } |
276 | } |
275 | } |
277 | } |
… | |
… | |
277 | static UV |
279 | static UV |
278 | get_length (void) |
280 | get_length (void) |
279 | { |
281 | { |
280 | UV res = get_u8 (); |
282 | UV res = get_u8 (); |
281 | |
283 | |
282 | if (res & 0x80) |
284 | if (expect_false (res & 0x80)) |
283 | { |
285 | { |
284 | int cnt = res & 0x7f; |
286 | U8 cnt = res & 0x7f; |
|
|
287 | |
|
|
288 | // this genewrates quite ugly code, but the overhead |
|
|
289 | // of copying the bytes for these lengths is probably so high |
|
|
290 | // that a slightly inefficient get_length won't matter. |
|
|
291 | |
|
|
292 | if (expect_false (cnt == 0)) |
|
|
293 | error ("illegal use of indefinite BER length form in primitive encoding (X.690 8.1.3.2)"); |
|
|
294 | |
|
|
295 | if (expect_false (cnt > UVSIZE)) |
|
|
296 | error ("BER value length too long (must fit into UV) or BER reserved value in length (X.690 8.1.3.5)"); |
|
|
297 | |
|
|
298 | want (cnt); |
|
|
299 | |
285 | res = 0; |
300 | res = 0; |
286 | |
301 | do |
287 | switch (cnt) |
302 | res = (res << 8) | *cur++; |
288 | { |
303 | while (--cnt); |
289 | case 0: |
|
|
290 | error ("indefinite ASN.1 lengths not supported"); |
|
|
291 | |
|
|
292 | case 0x7f: |
|
|
293 | error ("ASN.1 reserved value in length (X.690 8.1.3.5)"); |
|
|
294 | |
|
|
295 | default: |
|
|
296 | error ("ASN.1 length too long (only up to 2**64 octets supported)"); |
|
|
297 | |
|
|
298 | case 8: res = (res << 8) | get_u8 (); |
|
|
299 | case 7: res = (res << 8) | get_u8 (); |
|
|
300 | case 6: res = (res << 8) | get_u8 (); |
|
|
301 | case 5: res = (res << 8) | get_u8 (); |
|
|
302 | case 4: res = (res << 8) | get_u8 (); |
|
|
303 | case 3: res = (res << 8) | get_u8 (); |
|
|
304 | case 2: res = (res << 8) | get_u8 (); |
|
|
305 | case 1: res = (res << 8) | get_u8 (); |
|
|
306 | } |
|
|
307 | } |
304 | } |
308 | |
305 | |
309 | return res; |
306 | return res; |
310 | } |
307 | } |
311 | |
308 | |
312 | static SV * |
309 | static SV * |
313 | decode_int (void) |
310 | decode_int (UV len) |
314 | { |
311 | { |
315 | UV len = get_length (); |
|
|
316 | |
|
|
317 | if (!len) |
312 | if (!len) |
318 | error ("invalid integer length equal to zero (X.690 8.3.1)"); |
313 | error ("invalid BER_TYPE_INT length zero (X.690 8.3.1)"); |
319 | |
314 | |
320 | U8 *data = get_n (len); |
315 | U8 *data = get_n (len); |
321 | |
316 | |
322 | if (expect_false (len > 1)) |
317 | if (expect_false (len > 1)) |
323 | { |
318 | { |
324 | U16 mask = (data [0] << 8) | data [1] & 0xff80; |
319 | U16 mask = (data [0] << 8) | data [1] & 0xff80; |
325 | |
320 | |
326 | if (expect_false (mask == 0xff80 || mask == 0x0000)) |
321 | if (expect_false (mask == 0xff80 || mask == 0x0000)) |
327 | error ("illegal padding in integer (X.690 8.3.2)"); |
322 | error ("illegal padding in BER_TYPE_INT (X.690 8.3.2)"); |
328 | } |
323 | } |
329 | |
324 | |
330 | int negative = data [0] & 0x80; |
325 | int negative = data [0] & 0x80; |
331 | |
326 | |
332 | UV val = negative ? -1 : 0; // copy signbit to all bits |
327 | UV val = negative ? -1 : 0; // copy signbit to all bits |
333 | |
328 | |
334 | if (len > UVSIZE + (!negative && !*data)) |
329 | if (len > UVSIZE + (!negative && !*data)) |
335 | //printf ("len %d > %d + (!%d && !%d) = %d\n", len, UVSIZE, negative, *data, UVSIZE + (!negative && !*data));//D |
|
|
336 | error ("INTEGER overflow"); |
330 | error ("BER_TYPE_INT overflow"); |
337 | |
331 | |
338 | do |
332 | do |
339 | val = (val << 8) | *data++; |
333 | val = (val << 8) | *data++; |
340 | while (--len); |
334 | while (--len); |
341 | |
335 | |
… | |
… | |
343 | // but that's ok, as perl relies on it as well. |
337 | // but that's ok, as perl relies on it as well. |
344 | return negative ? newSViv ((IV)val) : newSVuv (val); |
338 | return negative ? newSViv ((IV)val) : newSVuv (val); |
345 | } |
339 | } |
346 | |
340 | |
347 | static SV * |
341 | static SV * |
348 | decode_data (void) |
342 | decode_data (UV len) |
349 | { |
343 | { |
350 | UV len = get_length (); |
|
|
351 | return newSVpvn ((char *)get_n (len), len); |
344 | return newSVpvn ((char *)get_n (len), len); |
352 | } |
345 | } |
353 | |
346 | |
354 | // helper for decode_object_identifier |
347 | // helper for decode_object_identifier |
355 | static char * |
348 | static char * |
… | |
… | |
383 | |
376 | |
384 | return buf; |
377 | return buf; |
385 | } |
378 | } |
386 | |
379 | |
387 | static SV * |
380 | static SV * |
388 | decode_oid (int relative) |
381 | decode_oid (UV len, int relative) |
389 | { |
382 | { |
390 | UV len = get_length (); |
|
|
391 | |
|
|
392 | if (len <= 0) |
383 | if (len <= 0) |
393 | { |
384 | { |
394 | error ("OBJECT IDENTIFIER length equal to zero"); |
385 | error ("BER_TYPE_OID length must not be zero"); |
395 | return &PL_sv_undef; |
386 | return &PL_sv_undef; |
396 | } |
387 | } |
397 | |
388 | |
398 | U8 *end = cur + len; |
389 | U8 *end = cur + len; |
399 | UV w = get_w (); |
390 | UV w = get_w (); |
… | |
… | |
401 | static char oid[MAX_OID_STRLEN]; // static, because too large for stack |
392 | static char oid[MAX_OID_STRLEN]; // static, because too large for stack |
402 | char *app = oid; |
393 | char *app = oid; |
403 | |
394 | |
404 | if (relative) |
395 | if (relative) |
405 | app = write_uv (app, w); |
396 | app = write_uv (app, w); |
|
|
397 | else |
|
|
398 | { |
|
|
399 | UV w1, w2; |
|
|
400 | |
406 | else if (w < 2 * 40) |
401 | if (w < 2 * 40) |
407 | { |
402 | (w1 = w / 40), (w2 = w % 40); |
|
|
403 | else |
|
|
404 | (w1 = 2), (w2 = w - 2 * 40); |
|
|
405 | |
408 | app = write_uv (app, (U8)w / 40); |
406 | app = write_uv (app, w1); |
409 | *app++ = '.'; |
407 | *app++ = '.'; |
410 | app = write_uv (app, (U8)w % 40); |
|
|
411 | } |
|
|
412 | else |
|
|
413 | { |
|
|
414 | app = write_uv (app, 2); |
408 | app = write_uv (app, w2); |
415 | *app++ = '.'; |
|
|
416 | app = write_uv (app, w - 2 * 40); |
|
|
417 | } |
409 | } |
418 | |
410 | |
419 | while (cur < end) |
411 | while (cur < end) |
420 | { |
412 | { |
421 | // we assume an oid component is never > 64 digits |
413 | // we assume an oid component is never > 64 digits |
… | |
… | |
430 | return newSVpvn (oid, app - oid); |
422 | return newSVpvn (oid, app - oid); |
431 | } |
423 | } |
432 | |
424 | |
433 | // TODO: this is unacceptably slow |
425 | // TODO: this is unacceptably slow |
434 | static SV * |
426 | static SV * |
435 | decode_ucs (int chrsize) |
427 | decode_ucs (UV len, int chrsize) |
436 | { |
428 | { |
437 | SV *res = NEWSV (0, 0); |
|
|
438 | |
|
|
439 | UV len = get_length (); |
|
|
440 | |
|
|
441 | if (len & (chrsize - 1)) |
429 | if (len & (chrsize - 1)) |
442 | croak ("BER_TYPE_UCS has an invalid number of octets (%d)", len); |
430 | croak ("BER_TYPE_UCS has an invalid number of octets (%d)", len); |
|
|
431 | |
|
|
432 | SV *res = NEWSV (0, 0); |
443 | |
433 | |
444 | while (len) |
434 | while (len) |
445 | { |
435 | { |
446 | U8 b1 = get_u8 (); |
436 | U8 b1 = get_u8 (); |
447 | U8 b2 = get_u8 (); |
437 | U8 b2 = get_u8 (); |
… | |
… | |
480 | if (tag == ASN_TAG_BER) |
470 | if (tag == ASN_TAG_BER) |
481 | tag = get_w (); |
471 | tag = get_w (); |
482 | |
472 | |
483 | if (constructed) |
473 | if (constructed) |
484 | { |
474 | { |
|
|
475 | want (1); |
|
|
476 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
477 | |
|
|
478 | if (expect_false (*cur == 0x80)) |
|
|
479 | { |
|
|
480 | // indefinite length |
|
|
481 | ++cur; |
|
|
482 | |
|
|
483 | for (;;) |
|
|
484 | { |
|
|
485 | want (2); |
|
|
486 | if (!cur [0] && !cur [1]) |
|
|
487 | { |
|
|
488 | cur += 2; |
|
|
489 | break; |
|
|
490 | } |
|
|
491 | |
|
|
492 | av_push (av, decode_ber ()); |
|
|
493 | } |
|
|
494 | } |
|
|
495 | else |
|
|
496 | { |
|
|
497 | UV len = get_length (); |
|
|
498 | UV seqend = (cur - buf) + len; |
|
|
499 | |
|
|
500 | while (cur < buf + seqend) |
|
|
501 | av_push (av, decode_ber ()); |
|
|
502 | |
|
|
503 | if (expect_false (cur > buf + seqend)) |
|
|
504 | croak ("CONSTRUCTED type %02x length overflow (0x%x 0x%x)\n", identifier, (int)(cur - buf), (int)seqend); |
|
|
505 | } |
|
|
506 | |
|
|
507 | res = newRV_inc ((SV *)av); |
|
|
508 | } |
|
|
509 | else |
|
|
510 | { |
485 | UV len = get_length (); |
511 | UV len = get_length (); |
486 | UV seqend = (cur - buf) + len; |
|
|
487 | AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
|
|
488 | |
512 | |
489 | while (cur < buf + seqend) |
|
|
490 | av_push (av, decode_ber ()); |
|
|
491 | |
|
|
492 | if (cur > buf + seqend) |
|
|
493 | croak ("constructed type %02x length overflow (0x%x 0x%x)\n", identifier, (int)(cur - buf), (int)seqend); |
|
|
494 | |
|
|
495 | res = newRV_inc ((SV *)av); |
|
|
496 | } |
|
|
497 | else |
|
|
498 | switch (profile_lookup (cur_profile, klass, tag)) |
513 | switch (profile_lookup (cur_profile, klass, tag)) |
499 | { |
514 | { |
500 | case BER_TYPE_NULL: |
515 | case BER_TYPE_NULL: |
501 | { |
516 | if (expect_false (len)) |
502 | UV len = get_length (); |
|
|
503 | |
|
|
504 | if (len) |
|
|
505 | croak ("BER_TYPE_NULL value with non-zero length %d encountered (X.690 8.8.2)", len); |
517 | croak ("BER_TYPE_NULL value with non-zero length %d encountered (X.690 8.8.2)", len); |
506 | |
518 | |
507 | res = &PL_sv_undef; |
519 | res = &PL_sv_undef; |
508 | } |
|
|
509 | break; |
520 | break; |
510 | |
521 | |
511 | case BER_TYPE_BOOL: |
522 | case BER_TYPE_BOOL: |
512 | { |
|
|
513 | UV len = get_length (); |
|
|
514 | |
|
|
515 | if (len != 1) |
523 | if (expect_false (len != 1)) |
516 | croak ("BER_TYPE_BOOLEAN value with invalid length %d encountered (X.690 8.2.1)", len); |
524 | croak ("BER_TYPE_BOOLEAN value with invalid length %d encountered (X.690 8.2.1)", len); |
517 | |
525 | |
518 | res = newSVcacheint (!!get_u8 ()); |
526 | res = newSVcacheint (!!get_u8 ()); |
519 | } |
|
|
520 | break; |
527 | break; |
521 | |
528 | |
522 | case BER_TYPE_OID: |
529 | case BER_TYPE_OID: |
523 | res = decode_oid (0); |
530 | res = decode_oid (len, 0); |
524 | break; |
531 | break; |
525 | |
532 | |
526 | case BER_TYPE_RELOID: |
533 | case BER_TYPE_RELOID: |
527 | res = decode_oid (1); |
534 | res = decode_oid (len, 1); |
528 | break; |
535 | break; |
529 | |
536 | |
530 | case BER_TYPE_INT: |
537 | case BER_TYPE_INT: |
531 | res = decode_int (); |
538 | res = decode_int (len); |
532 | break; |
539 | break; |
533 | |
540 | |
534 | case BER_TYPE_UTF8: |
541 | case BER_TYPE_UTF8: |
535 | res = decode_data (); |
542 | res = decode_data (len); |
536 | SvUTF8_on (res); |
543 | SvUTF8_on (res); |
537 | break; |
544 | break; |
538 | |
545 | |
539 | case BER_TYPE_BYTES: |
546 | case BER_TYPE_BYTES: |
540 | res = decode_data (); |
547 | res = decode_data (len); |
541 | break; |
548 | break; |
542 | |
549 | |
543 | case BER_TYPE_IPADDRESS: |
550 | case BER_TYPE_IPADDRESS: |
544 | { |
551 | { |
545 | UV len = get_length (); |
|
|
546 | |
|
|
547 | if (len != 4) |
552 | if (len != 4) |
548 | croak ("BER_TYPE_IPADDRESS type with invalid length %d encountered (RFC 2578 7.1.5)", len); |
553 | croak ("BER_TYPE_IPADDRESS type with invalid length %d encountered (RFC 2578 7.1.5)", len); |
549 | |
554 | |
550 | U8 c1 = get_u8 (); |
555 | U8 *data = get_n (4); |
551 | U8 c2 = get_u8 (); |
556 | res = newSVpvf ("%d.%d.%d.%d", data [0], data [1], data [2], data [3]); |
552 | U8 c3 = get_u8 (); |
|
|
553 | U8 c4 = get_u8 (); |
|
|
554 | |
|
|
555 | res = newSVpvf ("%d.%d.%d.%d", c1, c2, c3, c4); |
|
|
556 | } |
557 | } |
557 | break; |
558 | break; |
558 | |
559 | |
559 | case BER_TYPE_UCS2: |
560 | case BER_TYPE_UCS2: |
560 | res = decode_ucs (2); |
561 | res = decode_ucs (len, 2); |
561 | break; |
562 | break; |
562 | |
563 | |
563 | case BER_TYPE_UCS4: |
564 | case BER_TYPE_UCS4: |
564 | res = decode_ucs (4); |
565 | res = decode_ucs (len, 4); |
565 | break; |
566 | break; |
566 | |
567 | |
567 | case BER_TYPE_REAL: |
568 | case BER_TYPE_REAL: |
|
|
569 | error ("BER_TYPE_REAL not implemented"); |
|
|
570 | |
568 | case BER_TYPE_CROAK: |
571 | case BER_TYPE_CROAK: |
|
|
572 | croak ("class/tag %d/%d mapped to BER_TYPE_CROAK", klass, tag); |
|
|
573 | |
569 | default: |
574 | default: |
570 | croak ("unconfigured/unsupported class/tag %d/%d", klass, tag); |
575 | croak ("unconfigured/unsupported class/tag %d/%d", klass, tag); |
571 | } |
576 | } |
|
|
577 | } |
572 | |
578 | |
573 | AV *av = newAV (); |
579 | AV *av = newAV (); |
574 | av_fill (av, BER_ARRAYSIZE - 1); |
580 | av_fill (av, BER_ARRAYSIZE - 1); |
575 | AvARRAY (av)[BER_CLASS] = newSVcacheint (klass); |
581 | AvARRAY (av)[BER_CLASS] = newSVcacheint (klass); |
576 | AvARRAY (av)[BER_TAG ] = newSVcacheint (tag); |
582 | AvARRAY (av)[BER_TAG ] = newSVcacheint (tag); |
… | |
… | |
663 | } |
669 | } |
664 | |
670 | |
665 | static U8 * |
671 | static U8 * |
666 | put_length_at (UV val, U8 *cur) |
672 | put_length_at (UV val, U8 *cur) |
667 | { |
673 | { |
668 | if (val < 0x7fU) |
674 | if (val <= 0x7fU) |
669 | *cur++ = val; |
675 | *cur++ = val; |
670 | else |
676 | else |
671 | { |
677 | { |
672 | U8 *lenb = cur++; |
678 | U8 *lenb = cur++; |
673 | |
679 | |
674 | #if UVSIZE > 4 |
680 | #if UVSIZE > 4 |
675 | *cur = val >> 56; cur += *cur > 0; |
681 | *cur = val >> 56; cur += val >= ((UV)1 << (8 * 7)); |
676 | *cur = val >> 48; cur += *cur > 0; |
682 | *cur = val >> 48; cur += val >= ((UV)1 << (8 * 6)); |
677 | *cur = val >> 40; cur += *cur > 0; |
683 | *cur = val >> 40; cur += val >= ((UV)1 << (8 * 5)); |
678 | *cur = val >> 32; cur += *cur > 0; |
684 | *cur = val >> 32; cur += val >= ((UV)1 << (8 * 4)); |
679 | #endif |
685 | #endif |
680 | *cur = val >> 24; cur += *cur > 0; |
686 | *cur = val >> 24; cur += val >= ((UV)1 << (8 * 3)); |
681 | *cur = val >> 16; cur += *cur > 0; |
687 | *cur = val >> 16; cur += val >= ((UV)1 << (8 * 2)); |
682 | *cur = val >> 8; cur += *cur > 0; |
688 | *cur = val >> 8; cur += val >= ((UV)1 << (8 * 1)); |
683 | *cur = val ; cur += 1; |
689 | *cur = val ; cur += 1; |
684 | |
690 | |
685 | *lenb = 0x80 + cur - lenb - 1; |
691 | *lenb = 0x80 + cur - lenb - 1; |
686 | } |
692 | } |
687 | |
693 | |
… | |
… | |
689 | } |
695 | } |
690 | |
696 | |
691 | static void |
697 | static void |
692 | put_length (UV val) |
698 | put_length (UV val) |
693 | { |
699 | { |
694 | need (5 + val); |
700 | need (9 + val); |
695 | cur = put_length_at (val, cur); |
701 | cur = put_length_at (val, cur); |
696 | } |
702 | } |
697 | |
703 | |
698 | // return how many bytes the encoded length requires |
704 | // return how many bytes the encoded length requires |
699 | static int length_length (UV val) |
705 | static int length_length (UV val) |
700 | { |
706 | { |
701 | return val < 0x7fU |
707 | // use hashing with a DeBruin sequence, anyone? |
|
|
708 | return expect_true (val <= 0x7fU) |
702 | ? 1 |
709 | ? 1 |
703 | : 2 |
710 | : 2 |
704 | + (val > 0xffU) |
711 | + (val > 0x000000000000ffU) |
705 | + (val > 0xffffU) |
712 | + (val > 0x0000000000ffffU) |
706 | + (val > 0xffffffU) |
713 | + (val > 0x00000000ffffffU) |
707 | #if UVSIZE > 4 |
714 | #if UVSIZE > 4 |
708 | + (val > 0xffffffffU) |
715 | + (val > 0x000000ffffffffU) |
709 | + (val > 0xffffffffffU) |
716 | + (val > 0x0000ffffffffffU) |
710 | + (val > 0xffffffffffffU) |
717 | + (val > 0x00ffffffffffffU) |
711 | + (val > 0xffffffffffffffU) |
718 | + (val > 0xffffffffffffffU) |
712 | #endif |
719 | #endif |
713 | ; |
720 | ; |
714 | } |
721 | } |
715 | |
722 | |
… | |
… | |
924 | // and adjust later |
931 | // and adjust later |
925 | need (1); |
932 | need (1); |
926 | STRLEN mark = len_fixup_mark (); |
933 | STRLEN mark = len_fixup_mark (); |
927 | |
934 | |
928 | if (expect_false (!SvROK (data) || SvTYPE (SvRV (data)) != SVt_PVAV)) |
935 | if (expect_false (!SvROK (data) || SvTYPE (SvRV (data)) != SVt_PVAV)) |
929 | croak ("BER constructed data must be array-reference"); |
936 | croak ("BER CONSTRUCTED data must be array-reference"); |
930 | |
937 | |
931 | AV *av = (AV *)SvRV (data); |
938 | AV *av = (AV *)SvRV (data); |
932 | int fill = AvFILL (av); |
939 | int fill = AvFILL (av); |
933 | |
940 | |
934 | if (expect_false (SvRMAGICAL (av))) |
941 | if (expect_false (SvRMAGICAL (av))) |
935 | croak ("BER constructed data must not be tied"); |
942 | croak ("BER CONSTRUCTED data must not be tied"); |
936 | |
943 | |
937 | int i; |
944 | int i; |
938 | for (i = 0; i <= fill; ++i) |
945 | for (i = 0; i <= fill; ++i) |
939 | encode_ber (AvARRAY (av)[i]); |
946 | encode_ber (AvARRAY (av)[i]); |
940 | |
947 | |
… | |
… | |
995 | case BER_TYPE_UCS4: |
1002 | case BER_TYPE_UCS4: |
996 | encode_ucs (data, 4); |
1003 | encode_ucs (data, 4); |
997 | break; |
1004 | break; |
998 | |
1005 | |
999 | case BER_TYPE_REAL: |
1006 | case BER_TYPE_REAL: |
|
|
1007 | croak ("BER_TYPE_REAL not implemented"); |
|
|
1008 | |
1000 | case BER_TYPE_CROAK: |
1009 | case BER_TYPE_CROAK: |
|
|
1010 | croak ("class/tag %d/%d mapped to BER_TYPE_CROAK", klass, tag); |
|
|
1011 | |
1001 | default: |
1012 | default: |
1002 | croak ("unconfigured/unsupported class/tag %d/%d", klass, tag); |
1013 | croak ("unconfigured/unsupported class/tag %d/%d", klass, tag); |
1003 | } |
1014 | } |
1004 | |
1015 | |
1005 | } |
1016 | } |
… | |
… | |
1108 | PUSHs (sv_2mortal (tuple)); |
1119 | PUSHs (sv_2mortal (tuple)); |
1109 | |
1120 | |
1110 | if (ix) |
1121 | if (ix) |
1111 | PUSHs (sv_2mortal (newSViv (cur - buf))); |
1122 | PUSHs (sv_2mortal (newSViv (cur - buf))); |
1112 | else if (cur != end) |
1123 | else if (cur != end) |
1113 | error ("trailing garbage after BER data"); |
1124 | error ("trailing garbage after BER value"); |
1114 | } |
1125 | } |
1115 | |
1126 | |
1116 | void |
1127 | void |
1117 | ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef) |
1128 | ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef) |
1118 | PPCODE: |
1129 | PPCODE: |