ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-BER-XS/XS.xs
(Generate patch)

Comparing Convert-BER-XS/XS.xs (file contents):
Revision 1.5 by root, Fri Apr 19 23:50:53 2019 UTC vs.
Revision 1.20 by root, Sat Apr 20 17:04:35 2019 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5// C99 required 5// C99 required!
6// this is not just for comments, but also for
7// integer constant semantics,
8// sscanf format modifiers and more.
6 9
7enum { 10enum {
8 // ASN_TAG 11 // ASN_TAG
9 ASN_BOOLEAN = 0x01, 12 ASN_BOOLEAN = 0x01,
10 ASN_INTEGER32 = 0x02, 13 ASN_INTEGER = 0x02,
11 ASN_BIT_STRING = 0x03, 14 ASN_BIT_STRING = 0x03,
12 ASN_OCTET_STRING = 0x04, 15 ASN_OCTET_STRING = 0x04,
13 ASN_NULL = 0x05, 16 ASN_NULL = 0x05,
14 ASN_OBJECT_IDENTIFIER = 0x06, 17 ASN_OBJECT_IDENTIFIER = 0x06,
15 ASN_OID = 0x06, //X 18 ASN_OID = 0x06,
16 ASN_OBJECT_DESCRIPTOR = 0x07, //X 19 ASN_OBJECT_DESCRIPTOR = 0x07,
17 ASN_EXTERNAL = 0x08, //X 20 ASN_EXTERNAL = 0x08,
18 ASN_REAL = 0x09, //X 21 ASN_REAL = 0x09,
19 ASN_ENUMERATED = 0x0a, //X 22 ASN_ENUMERATED = 0x0a,
20 ASN_EMBEDDED_PDV = 0x0b, //X 23 ASN_EMBEDDED_PDV = 0x0b,
21 ASN_UTF8_STRING = 0x0c, //X 24 ASN_UTF8_STRING = 0x0c,
22 ASN_RELATIVE_OID = 0x0d, //X 25 ASN_RELATIVE_OID = 0x0d,
23 ASN_SEQUENCE = 0x10, 26 ASN_SEQUENCE = 0x10,
24 ASN_SET = 0x11, //X 27 ASN_SET = 0x11,
25 ASN_NUMERIC_STRING = 0x12, //X 28 ASN_NUMERIC_STRING = 0x12,
26 ASN_PRINTABLE_STRING = 0x13, //X 29 ASN_PRINTABLE_STRING = 0x13,
27 ASN_TELETEX_STRING = 0x14, //X 30 ASN_TELETEX_STRING = 0x14,
28 ASN_T61_STRING = 0x14, //X 31 ASN_T61_STRING = 0x14,
29 ASN_VIDEOTEX_STRING = 0x15, //X 32 ASN_VIDEOTEX_STRING = 0x15,
30 ASN_IA5_STRING = 0x16, //X 33 ASN_IA5_STRING = 0x16,
31 ASN_ASCII_STRING = 0x16, //X 34 ASN_ASCII_STRING = 0x16,
32 ASN_UTC_TIME = 0x17, //X 35 ASN_UTC_TIME = 0x17,
33 ASN_GENERALIZED_TIME = 0x18, //X 36 ASN_GENERALIZED_TIME = 0x18,
34 ASN_GRAPHIC_STRING = 0x19, //X 37 ASN_GRAPHIC_STRING = 0x19,
35 ASN_VISIBLE_STRING = 0x1a, //X 38 ASN_VISIBLE_STRING = 0x1a,
36 ASN_ISO646_STRING = 0x1a, //X 39 ASN_ISO646_STRING = 0x1a,
37 ASN_GENERAL_STRING = 0x1b, //X 40 ASN_GENERAL_STRING = 0x1b,
38 ASN_UNIVERSAL_STRING = 0x1c, //X 41 ASN_UNIVERSAL_STRING = 0x1c,
39 ASN_CHARACTER_STRING = 0x1d, //X 42 ASN_CHARACTER_STRING = 0x1d,
40 ASN_BMP_STRING = 0x1e, //X 43 ASN_BMP_STRING = 0x1e,
41 44
42 ASN_TAG_BER = 0x1f, 45 ASN_TAG_BER = 0x1f,
43 ASN_TAG_MASK = 0x1f, 46 ASN_TAG_MASK = 0x1f,
44 47
45 // primitive/constructed 48 // primitive/constructed
72 BER_TYPE_OID, 75 BER_TYPE_OID,
73 BER_TYPE_RELOID, 76 BER_TYPE_RELOID,
74 BER_TYPE_NULL, 77 BER_TYPE_NULL,
75 BER_TYPE_BOOL, 78 BER_TYPE_BOOL,
76 BER_TYPE_REAL, 79 BER_TYPE_REAL,
80 BER_TYPE_IPADDRESS,
77 BER_TYPE_CROAK, 81 BER_TYPE_CROAK,
78}; 82};
79 83
80enum { 84enum {
81 BER_CLASS = 0, 85 BER_CLASS = 0,
82 BER_TAG = 1, 86 BER_TAG = 1,
83 BER_CONSTRUCTED = 2, 87 BER_FLAGS = 2,
84 BER_DATA = 3, 88 BER_DATA = 3,
85 BER_ARRAYSIZE 89 BER_ARRAYSIZE
86}; 90};
87 91
88#define MAX_OID_STRLEN 4096 92#define MAX_OID_STRLEN 4096
89 93
90typedef void profile_type; 94typedef void profile_type;
91 95
92static profile_type *cur_profile, *default_profile; 96static profile_type *cur_profile, *default_profile;
93static SV *buf_sv; // encoding buffer 97static SV *buf_sv; // encoding buffer
94static U8 *buf, *cur, *end; // buffer start, current, end 98static U8 *buf, *cur, *end; // buffer start, current, end
99
100#if PERL_VERSION < 18
101# define utf8_to_uvchr_buf(s,e,l) utf8_to_uvchr (s, l)
102#endif
95 103
96#if __GNUC__ >= 3 104#if __GNUC__ >= 3
97# define expect(expr,value) __builtin_expect ((expr), (value)) 105# define expect(expr,value) __builtin_expect ((expr), (value))
98# define INLINE static inline 106# define INLINE static inline
99#else 107#else
129 137
130static profile_type * 138static profile_type *
131SvPROFILE (SV *profile) 139SvPROFILE (SV *profile)
132{ 140{
133 if (!SvOK (profile)) 141 if (!SvOK (profile))
134 profile = default_profile; 142 return default_profile;
135 143
136 if (!SvROK (profile)) 144 if (!SvROK (profile))
137 croak ("invalid profile"); 145 croak ("invalid profile");
138 146
139 profile = SvRV (profile); 147 profile = SvRV (profile);
154 return BER_TYPE_BYTES; 162 return BER_TYPE_BYTES;
155 163
156 return SvPVX (sv)[idx]; 164 return SvPVX (sv)[idx];
157} 165}
158 166
159static int 167static void
160profile_set (profile_type *profile, int klass, int tag, int type) 168profile_set (profile_type *profile, int klass, int tag, int type)
161{ 169{
162 SV *sv = (SV *)profile; 170 SV *sv = (SV *)profile;
163 U32 idx = (tag << 2) + klass; 171 U32 idx = (tag << 2) + klass;
164 STRLEN oldlen = SvCUR (sv); 172 STRLEN oldlen = SvCUR (sv);
173 181
174 SvPVX (sv)[idx] = type; 182 SvPVX (sv)[idx] = type;
175} 183}
176 184
177static SV * 185static SV *
178profile_new () 186profile_new (void)
179{ 187{
180 SV *sv = newSVpvn ("", 0); 188 SV *sv = newSVpvn ("", 0);
181 189
182 static const struct { 190 static const struct {
183 int klass; 191 int klass;
184 int tag; 192 int tag;
185 int type; 193 int type;
186 } *celem, default_map[] = { 194 } *celem, default_map[] = {
187 { ASN_UNIVERSAL, ASN_BOOLEAN , BER_TYPE_BOOL }, 195 { ASN_UNIVERSAL, ASN_BOOLEAN , BER_TYPE_BOOL },
188 { ASN_UNIVERSAL, ASN_INTEGER32 , BER_TYPE_INT }, 196 { ASN_UNIVERSAL, ASN_INTEGER , BER_TYPE_INT },
189 { ASN_UNIVERSAL, ASN_NULL , BER_TYPE_NULL }, 197 { ASN_UNIVERSAL, ASN_NULL , BER_TYPE_NULL },
190 { ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, BER_TYPE_OID }, 198 { ASN_UNIVERSAL, ASN_OBJECT_IDENTIFIER, BER_TYPE_OID },
191 { ASN_UNIVERSAL, ASN_OBJECT_DESCRIPTOR, BER_TYPE_OID },
192 { ASN_UNIVERSAL, ASN_RELATIVE_OID , BER_TYPE_RELOID }, 199 { ASN_UNIVERSAL, ASN_RELATIVE_OID , BER_TYPE_RELOID },
193 { ASN_UNIVERSAL, ASN_REAL , BER_TYPE_REAL }, 200 { ASN_UNIVERSAL, ASN_REAL , BER_TYPE_REAL },
201 { ASN_UNIVERSAL, ASN_ENUMERATED , BER_TYPE_INT },
194 { ASN_UNIVERSAL, ASN_UTF8_STRING , BER_TYPE_UTF8 }, 202 { ASN_UNIVERSAL, ASN_UTF8_STRING , BER_TYPE_UTF8 },
195 { ASN_UNIVERSAL, ASN_BMP_STRING , BER_TYPE_UCS2 }, 203 { ASN_UNIVERSAL, ASN_BMP_STRING , BER_TYPE_UCS2 },
196 { ASN_UNIVERSAL, ASN_UNIVERSAL_STRING , BER_TYPE_UCS4 }, 204 { ASN_UNIVERSAL, ASN_UNIVERSAL_STRING , BER_TYPE_UCS4 },
197 }; 205 };
198 206
199 //const_iv (SNMP_IPADDRESS)
200 //const_iv (SNMP_COUNTER32)
201 //const_iv (SNMP_UNSIGNED32)
202 //const_iv (SNMP_TIMETICKS)
203 //const_iv (SNMP_OPAQUE)
204 //const_iv (SNMP_COUNTER64)
205
206 for (celem = default_map + sizeof (default_map) / sizeof (default_map [0]); celem > default_map; celem--) 207 for (celem = default_map + sizeof (default_map) / sizeof (default_map [0]); celem-- > default_map; )
207 profile_set ((void *)sv, celem->klass, celem->tag, celem->type); 208 profile_set ((profile_type *)sv, celem->klass, celem->tag, celem->type);
208 209
209 return sv_bless (newRV_noinc (sv), profile_stash); 210 return sv_bless (newRV_noinc (sv), profile_stash);
210} 211}
211 212
212///////////////////////////////////////////////////////////////////////////// 213/////////////////////////////////////////////////////////////////////////////
247 248
248 return *cur++; 249 return *cur++;
249} 250}
250 251
251// get ber-encoded integer (i.e. pack "w") 252// get ber-encoded integer (i.e. pack "w")
252static U32 253static UV
253get_w (void) 254get_w (void)
254{ 255{
255 U32 res = 0; 256 UV res = 0;
257 U8 c = get_u8 ();
258
259 if (expect_false (c == 0x80))
260 error ("illegal BER padding (X.690 8.1.2.4.2, 8.19.2)");
256 261
257 for (;;) 262 for (;;)
258 { 263 {
259 U8 c = get_u8 ();
260 res = (res << 7) | (c & 0x7f); 264 res = (res << 7) | (c & 0x7f);
261 265
262 if (!(c & 0x80)) 266 if (!(c & 0x80))
263 return res; 267 return res;
264 }
265}
266 268
269 c = get_u8 ();
270 }
271}
272
267static U32 273static UV
268get_length (void) 274get_length (void)
269{ 275{
270 U32 res = get_u8 (); 276 UV res = get_u8 ();
271 277
272 if (res & 0x80) 278 if (res & 0x80)
273 { 279 {
274 int cnt = res & 0x7f; 280 int cnt = res & 0x7f;
275 res = 0; 281 res = 0;
276 282
277 switch (cnt) 283 switch (cnt)
278 { 284 {
279 case 0: 285 case 0:
280 error ("indefinite ASN.1 lengths not supported"); 286 error ("indefinite ASN.1 lengths not supported");
281 return 0; 287
288 case 0x7f:
289 error ("ASN.1 reserved value in length (X.690 8.1.3.5)");
282 290
283 default: 291 default:
284 error ("ASN.1 length too long"); 292 error ("ASN.1 length too long (only up to 2**64 octets supported)");
285 return 0;
286 293
294 case 8: res = (res << 8) | get_u8 ();
295 case 7: res = (res << 8) | get_u8 ();
296 case 6: res = (res << 8) | get_u8 ();
297 case 5: res = (res << 8) | get_u8 ();
287 case 4: res = (res << 8) | get_u8 (); 298 case 4: res = (res << 8) | get_u8 ();
288 case 3: res = (res << 8) | get_u8 (); 299 case 3: res = (res << 8) | get_u8 ();
289 case 2: res = (res << 8) | get_u8 (); 300 case 2: res = (res << 8) | get_u8 ();
290 case 1: res = (res << 8) | get_u8 (); 301 case 1: res = (res << 8) | get_u8 ();
291 } 302 }
293 304
294 return res; 305 return res;
295} 306}
296 307
297static SV * 308static SV *
298decode_int () 309decode_int (void)
299{ 310{
300 int len = get_length (); 311 UV len = get_length ();
301 312
302 if (len <= 0) 313 if (!len)
303 {
304 error ("integer length equal to zero"); 314 error ("invalid integer length equal to zero (X.690 8.3.1)");
305 return 0;
306 }
307 315
308 U8 *data = get_n (len); 316 U8 *data = get_n (len);
317
318 if (expect_false (len > 1))
319 {
320 U16 mask = (data [0] << 8) | data [1] & 0xff80;
321
322 if (expect_false (mask == 0xff80 || mask == 0x0000))
323 error ("illegal padding in integer (X.690 8.3.2)");
324 }
309 325
310 int negative = data [0] & 0x80; 326 int negative = data [0] & 0x80;
311 327
312 UV val = negative ? -1 : 0; // copy signbit to all bits 328 UV val = negative ? -1 : 0; // copy signbit to all bits
313 329
314 do 330 do
315 val = (val << 8) | *data++; 331 val = (val << 8) | *data++;
316 while (--len); 332 while (--len);
317 333
318 // the cats to IV relies on implementation-defined behaviour (two's complement cast) 334 // the cast to IV relies on implementation-defined behaviour (two's complement cast)
319 // but that's ok, as perl relies on it as well. 335 // but that's ok, as perl relies on it as well.
320 return negative ? newSViv ((IV)val) : newSVuv (val); 336 return negative ? newSViv ((IV)val) : newSVuv (val);
321} 337}
322 338
323static SV * 339static SV *
324decode_data (void) 340decode_data (void)
325{ 341{
326 U32 len = get_length (); 342 UV len = get_length ();
327 U8 *data = get_n (len);
328 return newSVpvn ((char *)data, len); 343 return newSVpvn ((char *)get_n (len), len);
329} 344}
330 345
331// gelper for decode_object_identifier 346// helper for decode_object_identifier
332static char * 347static char *
333write_uv (char *buf, U32 u) 348write_uv (char *buf, UV u)
334{ 349{
335 // the one-digit case is absolutely predominant, so this pays off (hopefully) 350 // the one-digit case is absolutely predominant, so this pays off (hopefully)
336 if (expect_true (u < 10)) 351 if (expect_true (u < 10))
337 *buf++ = u + '0'; 352 *buf++ = u + '0';
338 else 353 else
339 { 354 {
355 // this *could* be done much faster using branchless fixed-point arithmetics
340 char *beg = buf; 356 char *beg = buf;
341 357
342 do 358 do
343 { 359 {
344 *buf++ = u % 10 + '0'; 360 *buf++ = u % 10 + '0';
345 u /= 10; 361 u /= 10;
346 } 362 }
347 while (u); 363 while (u);
348 364
349 // reverse digits 365 // reverse digits
350 for (char *ptr = buf; --ptr != beg; ++beg) 366 char *ptr = buf;
367 while (--ptr > beg)
351 { 368 {
352 char c = *ptr; 369 char c = *ptr;
353 *ptr = *beg; 370 *ptr = *beg;
354 *beg = c; 371 *beg = c;
372 ++beg;
355 } 373 }
356 } 374 }
357 375
358 return buf; 376 return buf;
359} 377}
360 378
361static SV * 379static SV *
362decode_oid (int relative) 380decode_oid (int relative)
363{ 381{
364 U32 len = get_length (); 382 UV len = get_length ();
365 383
366 if (len <= 0) 384 if (len <= 0)
367 { 385 {
368 error ("OBJECT IDENTIFIER length equal to zero"); 386 error ("OBJECT IDENTIFIER length equal to zero");
369 return &PL_sv_undef; 387 return &PL_sv_undef;
370 } 388 }
371 389
372 U8 *end = cur + len; 390 U8 *end = cur + len;
373 U32 w = get_w (); 391 UV w = get_w ();
374 392
375 static char oid[MAX_OID_STRLEN]; // must be static 393 static char oid[MAX_OID_STRLEN]; // static, becaueds too large for stack
376 char *app = oid; 394 char *app = oid;
377 395
378 if (relative) 396 if (relative)
379 app = write_uv (app, w); 397 app = write_uv (app, w);
380 else 398 else if (w < 2 * 40)
381 { 399 {
382 app = write_uv (app, (U8)w / 40); 400 app = write_uv (app, (U8)w / 40);
383 *app++ = '.'; 401 *app++ = '.';
384 app = write_uv (app, (U8)w % 40); 402 app = write_uv (app, (U8)w % 40);
385 } 403 }
404 else
405 {
406 app = write_uv (app, 2);
407 *app++ = '.';
408 app = write_uv (app, w - 2 * 40);
409 }
386 410
411 while (cur < end)
412 {
387 // we assume an oid component is never > 64 bytes 413 // we assume an oid component is never > 64 digits
388 while (cur < end && oid + sizeof (oid) - app > 64) 414 if (oid + sizeof (oid) - app < 64)
389 { 415 croak ("BER_TYPE_OID to long to decode");
416
390 w = get_w (); 417 w = get_w ();
391 *app++ = '.'; 418 *app++ = '.';
392 app = write_uv (app, w); 419 app = write_uv (app, w);
393 } 420 }
394 421
395 return newSVpvn (oid, app - oid); 422 return newSVpvn (oid, app - oid);
396} 423}
397 424
425// TODO: this is unacceptably slow
398static SV * 426static SV *
427decode_ucs (int chrsize)
428{
429 SV *res = NEWSV (0, 0);
430
431 UV len = get_length ();
432
433 if (len & (chrsize - 1))
434 croak ("BER_TYPE_UCS has an invalid number of octets (%d)", len);
435
436 while (len)
437 {
438 U8 b1 = get_u8 ();
439 U8 b2 = get_u8 ();
440 U32 chr = (b1 << 8) | b2;
441
442 if (chrsize == 4)
443 {
444 U8 b3 = get_u8 ();
445 U8 b4 = get_u8 ();
446 chr = (chr << 16) | (b3 << 8) | b4;
447 }
448
449 U8 uchr [UTF8_MAXBYTES];
450 int uclen = uvuni_to_utf8 (uchr, chr) - uchr;
451
452 sv_catpvn (res, (const char *)uchr, uclen);
453 len -= chrsize;
454 }
455
456 SvUTF8_on (res);
457
458 return res;
459}
460
461static SV *
399decode_ber () 462decode_ber (void)
400{ 463{
401 int identifier = get_u8 (); 464 int identifier = get_u8 ();
402 465
403 SV *res; 466 SV *res;
404 467
407 int tag = identifier & ASN_TAG_MASK; 470 int tag = identifier & ASN_TAG_MASK;
408 471
409 if (tag == ASN_TAG_BER) 472 if (tag == ASN_TAG_BER)
410 tag = get_w (); 473 tag = get_w ();
411 474
412 if (tag == ASN_TAG_BER)
413 tag = get_w ();
414
415 if (constructed) 475 if (constructed)
416 { 476 {
417 U32 len = get_length (); 477 UV len = get_length ();
418 U32 seqend = (cur - buf) + len; 478 UV seqend = (cur - buf) + len;
419 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 479 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
420 480
421 while (cur < buf + seqend) 481 while (cur < buf + seqend)
422 av_push (av, decode_ber ()); 482 av_push (av, decode_ber ());
423 483
424 if (cur > buf + seqend) 484 if (cur > buf + seqend)
425 croak ("constructed type %02x overflow (%x %x)\n", identifier, cur - buf, seqend); 485 croak ("constructed type %02x length overflow (0x%x 0x%x)\n", identifier, (int)(cur - buf), (int)seqend);
426 486
427 res = newRV_inc ((SV *)av); 487 res = newRV_inc ((SV *)av);
428 } 488 }
429 else 489 else
430 switch (profile_lookup (cur_profile, klass, tag)) 490 switch (profile_lookup (cur_profile, klass, tag))
431 { 491 {
432 case BER_TYPE_NULL: 492 case BER_TYPE_NULL:
493 {
494 UV len = get_length ();
495
496 if (len)
497 croak ("BER_TYPE_NULL value with non-zero length %d encountered (X.690 8.8.2)", len);
498
433 res = &PL_sv_undef; 499 res = &PL_sv_undef;
500 }
434 break; 501 break;
435 502
436 case BER_TYPE_BOOL: 503 case BER_TYPE_BOOL:
437 { 504 {
438 U32 len = get_length (); 505 UV len = get_length ();
439 506
440 if (len != 1) 507 if (len != 1)
441 croak ("BOOLEAN type with invalid length %d encountered", len); 508 croak ("BER_TYPE_BOOLEAN value with invalid length %d encountered (X.690 8.2.1)", len);
442 509
443 res = newSVcacheint (get_u8 () ? 0 : 1); 510 res = newSVcacheint (!!get_u8 ());
444 } 511 }
445 break; 512 break;
446 513
447 case BER_TYPE_OID: 514 case BER_TYPE_OID:
448 res = decode_oid (0); 515 res = decode_oid (0);
463 530
464 case BER_TYPE_BYTES: 531 case BER_TYPE_BYTES:
465 res = decode_data (); 532 res = decode_data ();
466 break; 533 break;
467 534
535 case BER_TYPE_IPADDRESS:
536 {
537 UV len = get_length ();
538
539 if (len != 4)
540 croak ("BER_TYPE_IPADDRESS type with invalid length %d encountered (RFC 2578 7.1.5)", len);
541
542 U8 c1 = get_u8 ();
543 U8 c2 = get_u8 ();
544 U8 c3 = get_u8 ();
545 U8 c4 = get_u8 ();
546
547 res = newSVpvf ("%d.%d.%d.%d", c1, c2, c3, c4);
548 }
549 break;
550
551 case BER_TYPE_UCS2:
552 res = decode_ucs (2);
553 break;
554
555 case BER_TYPE_UCS4:
556 res = decode_ucs (4);
557 break;
558
468 case BER_TYPE_REAL: 559 case BER_TYPE_REAL:
469 case BER_TYPE_UCS2:
470 case BER_TYPE_UCS4:
471 case BER_TYPE_CROAK: 560 case BER_TYPE_CROAK:
472 default: 561 default:
473 croak ("unconfigured/unsupported class/tag %d/%d", klass, tag); 562 croak ("unconfigured/unsupported class/tag %d/%d", klass, tag);
474 } 563 }
475 564
476 AV *av = newAV (); 565 AV *av = newAV ();
477 av_fill (av, BER_ARRAYSIZE - 1); 566 av_fill (av, BER_ARRAYSIZE - 1);
478 AvARRAY (av)[BER_CLASS ] = newSVcacheint (klass); 567 AvARRAY (av)[BER_CLASS] = newSVcacheint (klass);
479 AvARRAY (av)[BER_TAG ] = newSVcacheint (tag); 568 AvARRAY (av)[BER_TAG ] = newSVcacheint (tag);
480 AvARRAY (av)[BER_CONSTRUCTED] = newSVcacheint (constructed ? 1 : 0); 569 AvARRAY (av)[BER_FLAGS] = newSVcacheint (constructed ? 1 : 0);
481 AvARRAY (av)[BER_DATA ] = res; 570 AvARRAY (av)[BER_DATA ] = res;
482 571
483 return newRV_noinc ((SV *)av); 572 return newRV_noinc ((SV *)av);
484} 573}
485 574
486///////////////////////////////////////////////////////////////////////////// 575/////////////////////////////////////////////////////////////////////////////
491strlen_sum (STRLEN l1, STRLEN l2) 580strlen_sum (STRLEN l1, STRLEN l2)
492{ 581{
493 size_t sum = l1 + l2; 582 size_t sum = l1 + l2;
494 583
495 if (sum < (size_t)l2 || sum != (size_t)(STRLEN)sum) 584 if (sum < (size_t)l2 || sum != (size_t)(STRLEN)sum)
496 croak ("JSON::XS: string size overflow"); 585 croak ("Convert::BER::XS: string size overflow");
497 586
498 return sum; 587 return sum;
499} 588}
500 589
501static void 590static void
502set_buf (SV *sv) 591set_buf (SV *sv)
503{ 592{
504 STRLEN len; 593 STRLEN len;
505 buf_sv = sv; 594 buf_sv = sv;
506 buf = SvPVbyte (buf_sv, len); 595 buf = (U8 *)SvPVbyte (buf_sv, len);
507 cur = buf; 596 cur = buf;
508 end = buf + len; 597 end = buf + len;
509} 598}
510 599
511/* similar to SvGROW, but somewhat safer and guarantees exponential realloc strategy */ 600/* similar to SvGROW, but somewhat safer and guarantees exponential realloc strategy */
525need (STRLEN len) 614need (STRLEN len)
526{ 615{
527 if (expect_false ((uintptr_t)(end - cur) < len)) 616 if (expect_false ((uintptr_t)(end - cur) < len))
528 { 617 {
529 STRLEN pos = cur - buf; 618 STRLEN pos = cur - buf;
530 buf = my_sv_grow (buf_sv, pos, len); 619 buf = (U8 *)my_sv_grow (buf_sv, pos, len);
531 cur = buf + pos; 620 cur = buf + pos;
532 end = buf + SvLEN (buf_sv) - 1; 621 end = buf + SvLEN (buf_sv) - 1;
533 } 622 }
534} 623}
535 624
539 need (1); 628 need (1);
540 *cur++ = val; 629 *cur++ = val;
541} 630}
542 631
543static void 632static void
544put_w_nocheck (U32 val) 633put_w_nocheck (UV val)
545{ 634{
635#if UVSIZE > 4
636 *cur = (val >> 7 * 9) | 0x80; cur += val >= ((UV)1 << (7 * 9));
637 *cur = (val >> 7 * 8) | 0x80; cur += val >= ((UV)1 << (7 * 8));
638 *cur = (val >> 7 * 7) | 0x80; cur += val >= ((UV)1 << (7 * 7));
639 *cur = (val >> 7 * 6) | 0x80; cur += val >= ((UV)1 << (7 * 6));
640 *cur = (val >> 7 * 5) | 0x80; cur += val >= ((UV)1 << (7 * 5));
641#endif
546 *cur = (val >> 7 * 4) | 0x80; cur += val >= (1 << (7 * 4)); 642 *cur = (val >> 7 * 4) | 0x80; cur += val >= ((UV)1 << (7 * 4));
547 *cur = (val >> 7 * 3) | 0x80; cur += val >= (1 << (7 * 3)); 643 *cur = (val >> 7 * 3) | 0x80; cur += val >= ((UV)1 << (7 * 3));
548 *cur = (val >> 7 * 2) | 0x80; cur += val >= (1 << (7 * 2)); 644 *cur = (val >> 7 * 2) | 0x80; cur += val >= ((UV)1 << (7 * 2));
549 *cur = (val >> 7 * 1) | 0x80; cur += val >= (1 << (7 * 1)); 645 *cur = (val >> 7 * 1) | 0x80; cur += val >= ((UV)1 << (7 * 1));
550 *cur = val & 0x7f; cur += 1; 646 *cur = val & 0x7f; cur += 1;
551} 647}
552 648
553static void 649static void
554put_w (U32 val) 650put_w (UV val)
555{ 651{
556 need (5); // we only handle up to 5 bytes 652 need (5); // we only handle up to 5 bytes
557 653
558 put_w_nocheck (val); 654 put_w_nocheck (val);
559} 655}
560 656
561static U8 * 657static U8 *
562put_length_at (U32 val, U8 *cur) 658put_length_at (UV val, U8 *cur)
563{ 659{
564 if (val < 0x7fU) 660 if (val < 0x7fU)
565 *cur++ = val; 661 *cur++ = val;
566 else 662 else
567 { 663 {
568 U8 *lenb = cur++; 664 U8 *lenb = cur++;
569 665
666#if UVSIZE > 4
667 *cur = val >> 56; cur += *cur > 0;
668 *cur = val >> 48; cur += *cur > 0;
669 *cur = val >> 40; cur += *cur > 0;
670 *cur = val >> 32; cur += *cur > 0;
671#endif
570 *cur = val >> 24; cur += *cur > 0; 672 *cur = val >> 24; cur += *cur > 0;
571 *cur = val >> 16; cur += *cur > 0; 673 *cur = val >> 16; cur += *cur > 0;
572 *cur = val >> 8; cur += *cur > 0; 674 *cur = val >> 8; cur += *cur > 0;
573 *cur = val ; cur += 1; 675 *cur = val ; cur += 1;
574 676
577 679
578 return cur; 680 return cur;
579} 681}
580 682
581static void 683static void
582put_length (U32 val) 684put_length (UV val)
583{ 685{
584 need (5); 686 need (5 + val);
585 cur = put_length_at (val, cur); 687 cur = put_length_at (val, cur);
586} 688}
587 689
588// return how many bytes the encoded length requires 690// return how many bytes the encoded length requires
589static int length_length (U32 val) 691static int length_length (UV val)
590{ 692{
591 return val < 0x7fU 693 return val < 0x7fU
592 ? 1 694 ? 1
593 : 2 + (val > 0xffU) + (val > 0xffffU) + (val > 0xffffffU); 695 : 2
696 + (val > 0xffU)
697 + (val > 0xffffU)
698 + (val > 0xffffffU)
699#if UVSIZE > 4
700 + (val > 0xffffffffU)
701 + (val > 0xffffffffffU)
702 + (val > 0xffffffffffffU)
703 + (val > 0xffffffffffffffU)
704#endif
705 ;
594} 706}
595 707
596static void 708static void
597encode_data (const char *ptr, STRLEN len) 709encode_data (const char *ptr, STRLEN len)
598{ 710{
599 put_length (len); 711 put_length (len);
600 need (len);
601 memcpy (cur, ptr, len); 712 memcpy (cur, ptr, len);
602 cur += len; 713 cur += len;
603} 714}
604 715
605static void 716static void
661 772
662 *lenb = cur - lenb - 1; 773 *lenb = cur - lenb - 1;
663} 774}
664 775
665// we don't know the length yet, so we optimistically 776// we don't know the length yet, so we optimistically
666// assume the length will need one octet later. if that 777// assume the length will need one octet later. If that
667// turns out to be wrong, we memove as needed. 778// turns out to be wrong, we memmove as needed.
668// mark the beginning 779// mark the beginning
669static STRLEN 780static STRLEN
670len_fixup_mark () 781len_fixup_mark (void)
671{ 782{
672 return cur++ - buf; 783 return cur++ - buf;
673} 784}
674 785
675// patch up the length 786// patch up the length
751 862
752 return (AV *)rv; 863 return (AV *)rv;
753} 864}
754 865
755static void 866static void
867encode_ucs (SV *data, int chrsize)
868{
869 STRLEN uchars = sv_len_utf8 (data);
870 STRLEN len;;
871 char *ptr = SvPVutf8 (data, len);
872
873 put_length (uchars * chrsize);
874
875 while (uchars--)
876 {
877 STRLEN uclen;
878 UV uchr = utf8_to_uvchr_buf ((U8 *)ptr, (U8 *)ptr + len, &uclen);
879
880 ptr += uclen;
881 len -= uclen;
882
883 if (chrsize == 4)
884 {
885 *cur++ = uchr >> 24;
886 *cur++ = uchr >> 16;
887 }
888
889 *cur++ = uchr >> 8;
890 *cur++ = uchr;
891 }
892}
893static void
756encode_ber (SV *tuple) 894encode_ber (SV *tuple)
757{ 895{
758 AV *av = ber_tuple (tuple); 896 AV *av = ber_tuple (tuple);
759 897
760 int klass = SvIV (AvARRAY (av)[BER_CLASS]); 898 int klass = SvIV (AvARRAY (av)[BER_CLASS]);
761 int tag = SvIV (AvARRAY (av)[BER_TAG]); 899 int tag = SvIV (AvARRAY (av)[BER_TAG]);
762 int constructed = SvIV (AvARRAY (av)[BER_CONSTRUCTED]) ? ASN_CONSTRUCTED : 0; 900 int constructed = SvIV (AvARRAY (av)[BER_FLAGS]) & 1 ? ASN_CONSTRUCTED : 0;
763 SV *data = AvARRAY (av)[BER_DATA]; 901 SV *data = AvARRAY (av)[BER_DATA];
764 902
765 int identifier = (klass << ASN_CLASS_SHIFT) | constructed; 903 int identifier = (klass << ASN_CLASS_SHIFT) | constructed;
766 904
767 if (expect_false (tag >= ASN_TAG_BER)) 905 if (expect_false (tag >= ASN_TAG_BER))
786 int fill = AvFILL (av); 924 int fill = AvFILL (av);
787 925
788 if (expect_false (SvRMAGICAL (av))) 926 if (expect_false (SvRMAGICAL (av)))
789 croak ("BER constructed data must not be tied"); 927 croak ("BER constructed data must not be tied");
790 928
929 int i;
791 for (int i = 0; i <= fill; ++i) 930 for (i = 0; i <= fill; ++i)
792 encode_ber (AvARRAY (av)[i]); 931 encode_ber (AvARRAY (av)[i]);
793 932
794 len_fixup (mark); 933 len_fixup (mark);
795 } 934 }
796 else 935 else
800 put_length (0); 939 put_length (0);
801 break; 940 break;
802 941
803 case BER_TYPE_BOOL: 942 case BER_TYPE_BOOL:
804 put_length (1); 943 put_length (1);
805 put_u8 (SvTRUE (data) ? 0xff : 0x00); 944 *cur++ = SvTRUE (data) ? 0xff : 0x00; // 0xff = DER/CER
806 break; 945 break;
807 946
808 case BER_TYPE_OID: 947 case BER_TYPE_OID:
809 encode_oid (data, 0); 948 encode_oid (data, 0);
810 break; 949 break;
831 const char *ptr = SvPVutf8 (data, len); 970 const char *ptr = SvPVutf8 (data, len);
832 encode_data (ptr, len); 971 encode_data (ptr, len);
833 } 972 }
834 break; 973 break;
835 974
975 case BER_TYPE_IPADDRESS:
976 {
977 U8 ip[4];
978 sscanf (SvPV_nolen (data), "%hhu.%hhu.%hhu.%hhu", ip + 0, ip + 1, ip + 2, ip + 3);
979 encode_data ((const char *)ip, sizeof (ip));
980 }
981 break;
982
983 case BER_TYPE_UCS2:
984 encode_ucs (data, 2);
985 break;
986
987 case BER_TYPE_UCS4:
988 encode_ucs (data, 4);
989 break;
990
836 case BER_TYPE_REAL: 991 case BER_TYPE_REAL:
837 case BER_TYPE_UCS2:
838 case BER_TYPE_UCS4:
839 case BER_TYPE_CROAK: 992 case BER_TYPE_CROAK:
840 default: 993 default:
841 croak ("unconfigured/unsupported class/tag %d/%d", klass, tag); 994 croak ("unconfigured/unsupported class/tag %d/%d", klass, tag);
842 } 995 }
843 996
859 const char *name; 1012 const char *name;
860 IV iv; 1013 IV iv;
861 } *civ, const_iv[] = { 1014 } *civ, const_iv[] = {
862#define const_iv(name) { # name, name }, 1015#define const_iv(name) { # name, name },
863 const_iv (ASN_BOOLEAN) 1016 const_iv (ASN_BOOLEAN)
864 const_iv (ASN_INTEGER32) 1017 const_iv (ASN_INTEGER)
865 const_iv (ASN_BIT_STRING) 1018 const_iv (ASN_BIT_STRING)
866 const_iv (ASN_OCTET_STRING) 1019 const_iv (ASN_OCTET_STRING)
867 const_iv (ASN_NULL) 1020 const_iv (ASN_NULL)
868 const_iv (ASN_OBJECT_IDENTIFIER) 1021 const_iv (ASN_OBJECT_IDENTIFIER)
869 const_iv (ASN_OBJECT_DESCRIPTOR) 1022 const_iv (ASN_OBJECT_DESCRIPTOR)
898 const_iv (ASN_CONTEXT) 1051 const_iv (ASN_CONTEXT)
899 const_iv (ASN_PRIVATE) 1052 const_iv (ASN_PRIVATE)
900 1053
901 const_iv (BER_CLASS) 1054 const_iv (BER_CLASS)
902 const_iv (BER_TAG) 1055 const_iv (BER_TAG)
903 const_iv (BER_CONSTRUCTED) 1056 const_iv (BER_FLAGS)
904 const_iv (BER_DATA) 1057 const_iv (BER_DATA)
905 1058
906 const_iv (BER_TYPE_BYTES) 1059 const_iv (BER_TYPE_BYTES)
907 const_iv (BER_TYPE_UTF8) 1060 const_iv (BER_TYPE_UTF8)
908 const_iv (BER_TYPE_UCS2) 1061 const_iv (BER_TYPE_UCS2)
911 const_iv (BER_TYPE_OID) 1064 const_iv (BER_TYPE_OID)
912 const_iv (BER_TYPE_RELOID) 1065 const_iv (BER_TYPE_RELOID)
913 const_iv (BER_TYPE_NULL) 1066 const_iv (BER_TYPE_NULL)
914 const_iv (BER_TYPE_BOOL) 1067 const_iv (BER_TYPE_BOOL)
915 const_iv (BER_TYPE_REAL) 1068 const_iv (BER_TYPE_REAL)
1069 const_iv (BER_TYPE_IPADDRESS)
916 const_iv (BER_TYPE_CROAK) 1070 const_iv (BER_TYPE_CROAK)
917 1071
918 const_iv (SNMP_IPADDRESS) 1072 const_iv (SNMP_IPADDRESS)
919 const_iv (SNMP_COUNTER32) 1073 const_iv (SNMP_COUNTER32)
920 const_iv (SNMP_UNSIGNED32) 1074 const_iv (SNMP_UNSIGNED32)
921 const_iv (SNMP_TIMETICKS) 1075 const_iv (SNMP_TIMETICKS)
922 const_iv (SNMP_OPAQUE) 1076 const_iv (SNMP_OPAQUE)
923 const_iv (SNMP_COUNTER64) 1077 const_iv (SNMP_COUNTER64)
924
925 }; 1078 };
926 1079
927 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 1080 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
928 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 1081 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
929
930 default_profile = profile_new ();
931} 1082}
932 1083
933SV * 1084SV *
934ber_decode (SV *ber, SV *profile = &PL_sv_undef) 1085ber_decode (SV *ber, SV *profile = &PL_sv_undef)
935 CODE: 1086 CODE:
936{ 1087{
937 cur_profile = SvPROFILE (profile); 1088 cur_profile = SvPROFILE (profile);
938 STRLEN len; 1089 STRLEN len;
939 buf = SvPVbyte (ber, len); 1090 buf = (U8 *)SvPVbyte (ber, len);
940 cur = buf; 1091 cur = buf;
941 end = buf + len; 1092 end = buf + len;
942 1093
943 RETVAL = decode_ber (); 1094 RETVAL = decode_ber ();
944} 1095}
945 OUTPUT: RETVAL 1096 OUTPUT: RETVAL
946 1097
947void 1098void
948ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *constructed = &PL_sv_undef, SV *data = &PL_sv_undef) 1099ber_is (SV *tuple, SV *klass = &PL_sv_undef, SV *tag = &PL_sv_undef, SV *flags = &PL_sv_undef, SV *data = &PL_sv_undef)
949 PPCODE: 1100 PPCODE:
950{ 1101{
951 if (!SvOK (tuple)) 1102 if (!SvOK (tuple))
952 XSRETURN_NO; 1103 XSRETURN_NO;
953 1104
955 croak ("ber_is: tuple must be BER tuple (array-ref)"); 1106 croak ("ber_is: tuple must be BER tuple (array-ref)");
956 1107
957 AV *av = (AV *)SvRV (tuple); 1108 AV *av = (AV *)SvRV (tuple);
958 1109
959 XPUSHs ( 1110 XPUSHs (
960 (!SvOK (klass) || SvIV (AvARRAY (av)[BER_CLASS ]) == SvIV (klass)) 1111 (!SvOK (klass) || SvIV (AvARRAY (av)[BER_CLASS]) == SvIV (klass))
961 && (!SvOK (tag) || SvIV (AvARRAY (av)[BER_TAG ]) == SvIV (tag)) 1112 && (!SvOK (tag) || SvIV (AvARRAY (av)[BER_TAG ]) == SvIV (tag))
962 && (!SvOK (constructed) || !SvIV (AvARRAY (av)[BER_CONSTRUCTED]) == !SvIV (constructed)) 1113 && (!SvOK (flags) || !SvIV (AvARRAY (av)[BER_FLAGS]) == !SvIV (flags))
963 && (!SvOK (data) || sv_eq (AvARRAY (av)[BER_DATA ], data)) 1114 && (!SvOK (data) || sv_eq (AvARRAY (av)[BER_DATA ], data))
964 ? &PL_sv_yes : &PL_sv_undef); 1115 ? &PL_sv_yes : &PL_sv_undef);
965} 1116}
966 1117
967void 1118void
968ber_is_seq (SV *tuple) 1119ber_is_seq (SV *tuple)
972 XSRETURN_UNDEF; 1123 XSRETURN_UNDEF;
973 1124
974 AV *av = ber_tuple (tuple); 1125 AV *av = ber_tuple (tuple);
975 1126
976 XPUSHs ( 1127 XPUSHs (
977 SvIV (AvARRAY (av)[BER_CLASS ]) == ASN_UNIVERSAL 1128 SvIV (AvARRAY (av)[BER_CLASS]) == ASN_UNIVERSAL
978 && SvIV (AvARRAY (av)[BER_TAG ]) == ASN_SEQUENCE 1129 && SvIV (AvARRAY (av)[BER_TAG ]) == ASN_SEQUENCE
979 && SvIV (AvARRAY (av)[BER_CONSTRUCTED]) 1130 && SvIV (AvARRAY (av)[BER_FLAGS])
980 ? AvARRAY (av)[BER_DATA] : &PL_sv_undef); 1131 ? AvARRAY (av)[BER_DATA] : &PL_sv_undef);
981} 1132}
982 1133
983void 1134void
984ber_is_i32 (SV *tuple, SV *value = &PL_sv_undef) 1135ber_is_int (SV *tuple, SV *value = &PL_sv_undef)
985 PPCODE: 1136 PPCODE:
986{ 1137{
987 if (!SvOK (tuple)) 1138 if (!SvOK (tuple))
988 XSRETURN_NO; 1139 XSRETURN_NO;
989 1140
990 AV *av = ber_tuple (tuple); 1141 AV *av = ber_tuple (tuple);
991 1142
992 IV data = SvIV (AvARRAY (av)[BER_DATA]); 1143 UV data = SvUV (AvARRAY (av)[BER_DATA]);
993 1144
994 XPUSHs ( 1145 XPUSHs (
995 SvIV (AvARRAY (av)[BER_CLASS ]) == ASN_UNIVERSAL 1146 SvIV (AvARRAY (av)[BER_CLASS]) == ASN_UNIVERSAL
996 && SvIV (AvARRAY (av)[BER_TAG ]) == ASN_INTEGER32 1147 && SvIV (AvARRAY (av)[BER_TAG ]) == ASN_INTEGER
997 && !SvIV (AvARRAY (av)[BER_CONSTRUCTED]) 1148 && !SvIV (AvARRAY (av)[BER_FLAGS])
998 && (!SvOK (value) || data == SvIV (value)) 1149 && (!SvOK (value) || data == SvUV (value))
999 ? sv_2mortal (data ? newSViv (data) : newSVpv ("0 but true", 0)) 1150 ? sv_2mortal (data ? newSVsv (AvARRAY (av)[BER_DATA]) : newSVpv ("0 but true", 0))
1000 : &PL_sv_undef); 1151 : &PL_sv_undef);
1001} 1152}
1002 1153
1003void 1154void
1004ber_is_oid (SV *tuple, SV *oid = &PL_sv_undef) 1155ber_is_oid (SV *tuple, SV *oid = &PL_sv_undef)
1008 XSRETURN_NO; 1159 XSRETURN_NO;
1009 1160
1010 AV *av = ber_tuple (tuple); 1161 AV *av = ber_tuple (tuple);
1011 1162
1012 XPUSHs ( 1163 XPUSHs (
1013 SvIV (AvARRAY (av)[BER_CLASS ]) == ASN_UNIVERSAL 1164 SvIV (AvARRAY (av)[BER_CLASS]) == ASN_UNIVERSAL
1014 && SvIV (AvARRAY (av)[BER_TAG ]) == ASN_OBJECT_IDENTIFIER 1165 && SvIV (AvARRAY (av)[BER_TAG ]) == ASN_OBJECT_IDENTIFIER
1015 && !SvIV (AvARRAY (av)[BER_CONSTRUCTED]) 1166 && !SvIV (AvARRAY (av)[BER_FLAGS])
1016 && (!SvOK (oid) || sv_eq (AvARRAY (av)[BER_DATA], oid)) 1167 && (!SvOK (oid) || sv_eq (AvARRAY (av)[BER_DATA], oid))
1017 ? newSVsv (AvARRAY (av)[BER_DATA]) : &PL_sv_undef); 1168 ? newSVsv (AvARRAY (av)[BER_DATA]) : &PL_sv_undef);
1018} 1169}
1019 1170
1020############################################################################# 1171#############################################################################
1033 SvCUR_set (buf_sv, cur - buf); 1184 SvCUR_set (buf_sv, cur - buf);
1034 XPUSHs (buf_sv); 1185 XPUSHs (buf_sv);
1035} 1186}
1036 1187
1037SV * 1188SV *
1038ber_i32 (IV iv) 1189ber_int (SV *sv)
1039 CODE: 1190 CODE:
1040{ 1191{
1041 AV *av = newAV (); 1192 AV *av = newAV ();
1042 av_fill (av, BER_ARRAYSIZE - 1); 1193 av_fill (av, BER_ARRAYSIZE - 1);
1043 AvARRAY (av)[BER_CLASS ] = newSVcacheint (ASN_UNIVERSAL); 1194 AvARRAY (av)[BER_CLASS] = newSVcacheint (ASN_UNIVERSAL);
1044 AvARRAY (av)[BER_TAG ] = newSVcacheint (ASN_INTEGER32); 1195 AvARRAY (av)[BER_TAG ] = newSVcacheint (ASN_INTEGER);
1045 AvARRAY (av)[BER_CONSTRUCTED] = newSVcacheint (0); 1196 AvARRAY (av)[BER_FLAGS] = newSVcacheint (0);
1046 AvARRAY (av)[BER_DATA ] = newSViv (iv); 1197 AvARRAY (av)[BER_DATA ] = newSVsv (sv);
1047 RETVAL = newRV_noinc ((SV *)av); 1198 RETVAL = newRV_noinc ((SV *)av);
1048} 1199}
1049 OUTPUT: RETVAL 1200 OUTPUT: RETVAL
1050 1201
1051# TODO: not arrayref, but elements? 1202# TODO: not arrayref, but elements?
1053ber_seq (SV *arrayref) 1204ber_seq (SV *arrayref)
1054 CODE: 1205 CODE:
1055{ 1206{
1056 AV *av = newAV (); 1207 AV *av = newAV ();
1057 av_fill (av, BER_ARRAYSIZE - 1); 1208 av_fill (av, BER_ARRAYSIZE - 1);
1058 AvARRAY (av)[BER_CLASS ] = newSVcacheint (ASN_UNIVERSAL); 1209 AvARRAY (av)[BER_CLASS] = newSVcacheint (ASN_UNIVERSAL);
1059 AvARRAY (av)[BER_TAG ] = newSVcacheint (ASN_SEQUENCE); 1210 AvARRAY (av)[BER_TAG ] = newSVcacheint (ASN_SEQUENCE);
1060 AvARRAY (av)[BER_CONSTRUCTED] = newSVcacheint (1); 1211 AvARRAY (av)[BER_FLAGS] = newSVcacheint (1);
1061 AvARRAY (av)[BER_DATA ] = newSVsv (arrayref); 1212 AvARRAY (av)[BER_DATA ] = newSVsv (arrayref);
1062 RETVAL = newRV_noinc ((SV *)av); 1213 RETVAL = newRV_noinc ((SV *)av);
1063} 1214}
1064 OUTPUT: RETVAL 1215 OUTPUT: RETVAL
1065 1216
1066MODULE = Convert::BER::XS PACKAGE = Convert::BER::XS::Profile 1217MODULE = Convert::BER::XS PACKAGE = Convert::BER::XS::Profile
1069new (SV *klass) 1220new (SV *klass)
1070 CODE: 1221 CODE:
1071 RETVAL = profile_new (); 1222 RETVAL = profile_new ();
1072 OUTPUT: RETVAL 1223 OUTPUT: RETVAL
1073 1224
1225void
1226set (SV *profile, int klass, int tag, int type)
1227 CODE:
1228 profile_set (SvPROFILE (profile), klass, tag, type);
1229
1230IV
1231get (SV *profile, int klass, int tag)
1232 CODE:
1233 RETVAL = profile_lookup (SvPROFILE (profile), klass, tag);
1234 OUTPUT: RETVAL
1235
1236void
1237_set_default (SV *profile)
1238 CODE:
1239 default_profile = SvPROFILE (profile);
1240
1241

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines