… | |
… | |
159 | return BER_TYPE_BYTES; |
159 | return BER_TYPE_BYTES; |
160 | |
160 | |
161 | return SvPVX (sv)[idx]; |
161 | return SvPVX (sv)[idx]; |
162 | } |
162 | } |
163 | |
163 | |
164 | static int |
164 | static void |
165 | profile_set (profile_type *profile, int klass, int tag, int type) |
165 | profile_set (profile_type *profile, int klass, int tag, int type) |
166 | { |
166 | { |
167 | SV *sv = (SV *)profile; |
167 | SV *sv = (SV *)profile; |
168 | U32 idx = (tag << 2) + klass; |
168 | U32 idx = (tag << 2) + klass; |
169 | STRLEN oldlen = SvCUR (sv); |
169 | STRLEN oldlen = SvCUR (sv); |
… | |
… | |
199 | { ASN_UNIVERSAL, ASN_UTF8_STRING , BER_TYPE_UTF8 }, |
199 | { ASN_UNIVERSAL, ASN_UTF8_STRING , BER_TYPE_UTF8 }, |
200 | { ASN_UNIVERSAL, ASN_BMP_STRING , BER_TYPE_UCS2 }, |
200 | { ASN_UNIVERSAL, ASN_BMP_STRING , BER_TYPE_UCS2 }, |
201 | { ASN_UNIVERSAL, ASN_UNIVERSAL_STRING , BER_TYPE_UCS4 }, |
201 | { ASN_UNIVERSAL, ASN_UNIVERSAL_STRING , BER_TYPE_UCS4 }, |
202 | }; |
202 | }; |
203 | |
203 | |
204 | for (celem = default_map + sizeof (default_map) / sizeof (default_map [0]); celem > default_map; celem--) |
204 | for (celem = default_map + sizeof (default_map) / sizeof (default_map [0]); celem-- > default_map; ) |
205 | profile_set ((void *)sv, celem->klass, celem->tag, celem->type); |
205 | profile_set ((profile_type *)sv, celem->klass, celem->tag, celem->type); |
206 | |
206 | |
207 | return sv_bless (newRV_noinc (sv), profile_stash); |
207 | return sv_bless (newRV_noinc (sv), profile_stash); |
208 | } |
208 | } |
209 | |
209 | |
210 | ///////////////////////////////////////////////////////////////////////////// |
210 | ///////////////////////////////////////////////////////////////////////////// |
… | |
… | |
343 | u /= 10; |
343 | u /= 10; |
344 | } |
344 | } |
345 | while (u); |
345 | while (u); |
346 | |
346 | |
347 | // reverse digits |
347 | // reverse digits |
348 | for (char *ptr = buf; --ptr != beg; ++beg) |
348 | char *ptr = buf; |
|
|
349 | while (--ptr != beg) |
349 | { |
350 | { |
350 | char c = *ptr; |
351 | char c = *ptr; |
351 | *ptr = *beg; |
352 | *ptr = *beg; |
352 | *beg = c; |
353 | *beg = c; |
|
|
354 | ++beg; |
353 | } |
355 | } |
354 | } |
356 | } |
355 | |
357 | |
356 | return buf; |
358 | return buf; |
357 | } |
359 | } |
… | |
… | |
557 | static void |
559 | static void |
558 | set_buf (SV *sv) |
560 | set_buf (SV *sv) |
559 | { |
561 | { |
560 | STRLEN len; |
562 | STRLEN len; |
561 | buf_sv = sv; |
563 | buf_sv = sv; |
562 | buf = SvPVbyte (buf_sv, len); |
564 | buf = (U8 *)SvPVbyte (buf_sv, len); |
563 | cur = buf; |
565 | cur = buf; |
564 | end = buf + len; |
566 | end = buf + len; |
565 | } |
567 | } |
566 | |
568 | |
567 | /* similar to SvGROW, but somewhat safer and guarantees exponential realloc strategy */ |
569 | /* similar to SvGROW, but somewhat safer and guarantees exponential realloc strategy */ |
… | |
… | |
581 | need (STRLEN len) |
583 | need (STRLEN len) |
582 | { |
584 | { |
583 | if (expect_false ((uintptr_t)(end - cur) < len)) |
585 | if (expect_false ((uintptr_t)(end - cur) < len)) |
584 | { |
586 | { |
585 | STRLEN pos = cur - buf; |
587 | STRLEN pos = cur - buf; |
586 | buf = my_sv_grow (buf_sv, pos, len); |
588 | buf = (U8 *)my_sv_grow (buf_sv, pos, len); |
587 | cur = buf + pos; |
589 | cur = buf + pos; |
588 | end = buf + SvLEN (buf_sv) - 1; |
590 | end = buf + SvLEN (buf_sv) - 1; |
589 | } |
591 | } |
590 | } |
592 | } |
591 | |
593 | |
… | |
… | |
817 | put_length (uchars * chrsize); |
819 | put_length (uchars * chrsize); |
818 | |
820 | |
819 | while (uchars--) |
821 | while (uchars--) |
820 | { |
822 | { |
821 | STRLEN uclen; |
823 | STRLEN uclen; |
822 | UV uchr = utf8_to_uvchr_buf (ptr, ptr + len, &uclen); |
824 | UV uchr = utf8_to_uvchr_buf ((U8 *)ptr, (U8 *)ptr + len, &uclen); |
823 | |
825 | |
824 | ptr += uclen; |
826 | ptr += uclen; |
825 | len -= uclen; |
827 | len -= uclen; |
826 | |
828 | |
827 | if (chrsize == 4) |
829 | if (chrsize == 4) |
… | |
… | |
868 | int fill = AvFILL (av); |
870 | int fill = AvFILL (av); |
869 | |
871 | |
870 | if (expect_false (SvRMAGICAL (av))) |
872 | if (expect_false (SvRMAGICAL (av))) |
871 | croak ("BER constructed data must not be tied"); |
873 | croak ("BER constructed data must not be tied"); |
872 | |
874 | |
|
|
875 | int i; |
873 | for (int i = 0; i <= fill; ++i) |
876 | for (i = 0; i <= fill; ++i) |
874 | encode_ber (AvARRAY (av)[i]); |
877 | encode_ber (AvARRAY (av)[i]); |
875 | |
878 | |
876 | len_fixup (mark); |
879 | len_fixup (mark); |
877 | } |
880 | } |
878 | else |
881 | else |
… | |
… | |
1028 | ber_decode (SV *ber, SV *profile = &PL_sv_undef) |
1031 | ber_decode (SV *ber, SV *profile = &PL_sv_undef) |
1029 | CODE: |
1032 | CODE: |
1030 | { |
1033 | { |
1031 | cur_profile = SvPROFILE (profile); |
1034 | cur_profile = SvPROFILE (profile); |
1032 | STRLEN len; |
1035 | STRLEN len; |
1033 | buf = SvPVbyte (ber, len); |
1036 | buf = (U8 *)SvPVbyte (ber, len); |
1034 | cur = buf; |
1037 | cur = buf; |
1035 | end = buf + len; |
1038 | end = buf + len; |
1036 | |
1039 | |
1037 | RETVAL = decode_ber (); |
1040 | RETVAL = decode_ber (); |
1038 | } |
1041 | } |