| 1 |
|
| MODULE = CryptX PACKAGE = Crypt::ASN1 |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| SV * |
| 6 |
|
| asn1_decode_der(SV *der, SV *opts = &PL_sv_undef) |
| 7 |
|
| CODE: |
| 8 |
|
| { |
| 9 |
41 |
| STRLEN der_len = 0; |
| 10 |
41 |
| unsigned char *der_ptr = (unsigned char *)SvPVbyte(der, der_len); |
| 11 |
41 |
| unsigned long inlen = (unsigned long)der_len; |
| 12 |
41 |
| ltc_asn1_list *list = NULL; |
| 13 |
|
| int rv; |
| 14 |
41 |
| asn1_opts_t o = { 0, 0, 0, NULL }; |
| 15 |
|
| |
| 16 |
41 |
▶ | if (SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
12 |
29 |
41 |
| if (SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) { |
12 |
0 |
12 |
|
| 17 |
12 |
| HV *h = (HV *)SvRV(opts); |
| 18 |
|
| SV **sv; |
| 19 |
12 |
▶ | if ((sv = hv_fetchs(h, "int", 0)) && SvOK(*sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(h, "int", 0)) && SvOK(*sv)) { |
7 |
5 |
12 |
| if ((sv = hv_fetchs(h, "int", 0)) && SvOK(*sv)) { |
7 |
0 |
7 |
|
| 20 |
7 |
| const char *v = SvPV_nolen(*sv); |
| 21 |
7 |
▶ | if (strEQ(v, "hex")) o.int_fmt = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(v, "hex")) o.int_fmt = 1; |
3 |
4 |
7 |
|
| 22 |
4 |
▶ | else if (strEQ(v, "bytes")) o.int_fmt = 2; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(v, "bytes")) o.int_fmt = 2; |
4 |
0 |
4 |
|
| 23 |
|
| } |
| 24 |
12 |
▶ | if ((sv = hv_fetchs(h, "bin", 0)) && SvOK(*sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(h, "bin", 0)) && SvOK(*sv)) { |
5 |
7 |
12 |
| if ((sv = hv_fetchs(h, "bin", 0)) && SvOK(*sv)) { |
5 |
0 |
5 |
|
| 25 |
5 |
| const char *v = SvPV_nolen(*sv); |
| 26 |
5 |
▶ | if (strEQ(v, "hex")) o.bin_fmt = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(v, "hex")) o.bin_fmt = 1; |
2 |
3 |
5 |
|
| 27 |
3 |
▶ | else if (strEQ(v, "base64")) o.bin_fmt = 2; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(v, "base64")) o.bin_fmt = 2; |
3 |
0 |
3 |
|
| 28 |
|
| } |
| 29 |
12 |
▶ | if ((sv = hv_fetchs(h, "dt", 0)) && SvOK(*sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(h, "dt", 0)) && SvOK(*sv)) { |
4 |
8 |
12 |
| if ((sv = hv_fetchs(h, "dt", 0)) && SvOK(*sv)) { |
4 |
0 |
4 |
|
| 30 |
4 |
| const char *v = SvPV_nolen(*sv); |
| 31 |
4 |
▶ | if (strEQ(v, "epoch")) o.dt_fmt = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(v, "epoch")) o.dt_fmt = 1; |
4 |
0 |
4 |
|
| 32 |
|
| } |
| 33 |
12 |
▶ | if ((sv = hv_fetchs(h, "oidmap", 0)) && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(h, "oidmap", 0)) && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVHV) { |
1 |
11 |
12 |
| if ((sv = hv_fetchs(h, "oidmap", 0)) && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVHV) { |
1 |
0 |
1 |
| if ((sv = hv_fetchs(h, "oidmap", 0)) && SvROK(*sv) && SvTYPE(SvRV(*sv)) == SVt_PVHV) { |
1 |
0 |
1 |
|
| 34 |
1 |
| o.oidmap = (HV *)SvRV(*sv); |
| 35 |
|
| } |
| 36 |
|
| } |
| 37 |
|
| |
| 38 |
41 |
| rv = der_decode_sequence_flexi(der_ptr, &inlen, &list); |
| 39 |
41 |
▶ | if (rv != CRYPT_OK) croak("FATAL: asn1_decode_der failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: asn1_decode_der failed: %s", error_to_string(rv)); |
0 |
41 |
41 |
|
| 40 |
|
| |
| 41 |
41 |
| RETVAL = newRV_noinc(s_ltc_asn1_to_perl(aTHX_ list, o)); |
| 42 |
40 |
| der_sequence_free(list); |
| 43 |
|
| } |
| 44 |
|
| OUTPUT: |
| 45 |
|
| RETVAL |
| 46 |
|
| |
| 47 |
|
| SV * |
| 48 |
|
| _asn1_encode_der(SV *tree) |
| 49 |
|
| CODE: |
| 50 |
|
| { |
| 51 |
|
| AV *nodes; |
| 52 |
|
| |
| 53 |
42 |
▶ | if (!SvROK(tree) || SvTYPE(SvRV(tree)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(tree) || SvTYPE(SvRV(tree)) != SVt_PVAV) |
42 |
0 |
42 |
| if (!SvROK(tree) || SvTYPE(SvRV(tree)) != SVt_PVAV) |
0 |
42 |
42 |
|
| 54 |
0 |
| croak("FATAL: _asn1_encode_der: argument must be an arrayref"); |
| 55 |
|
| |
| 56 |
42 |
| nodes = (AV *)SvRV(tree); |
| 57 |
42 |
| RETVAL = newSVpvn("", 0); |
| 58 |
42 |
| s_asn1_encode_nodes(aTHX_ RETVAL, nodes); |
| 59 |
|
| } |
| 60 |
|
| OUTPUT: |
| 61 |
|
| RETVAL |