include/psaml/psaml_abi.h

filter: Statementstmt 89.1% 33 / 37 Branchbran 54.3% 25 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 69.8% 58 / 83 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/psaml/psaml_signature.h ↑ Summary PSAML.c »
1 #ifndef PSAML_ABI_H
2 #define PSAML_ABI_H
3  
4 /* Resolvers for the three house C ABIs Punk::SAML builds on:
5 * frx_abi (File::Raw::XML - the tree, by_id, the canonical form)
6 * jws_abi (Crypt::JWS - signatures, digests, HMAC, CSPRNG, ct-eq,
7 * and the public key out of an X.509 certificate)
8 * fetch_abi (Fetch - the metadata request)
9 *
10 * Each is resolved lazily through the house _abi_ptr consumer pattern
11 * and version-checked. All three are hard prerequisites, so a failure to
12 * resolve is a boot-environment error and croaks by name.
13 *
14 * Punk itself is NOT here: pk_abi.h is an observer table with no
15 * install_kw, so there is nothing to consume from it, and Punk is
16 * reached by ordinary method dispatch the way Punk-Feed and
17 * Punk-Challenge reach it. */
18  
19 #include "frx_abi.h"
20 #include "jws_abi.h"
21 #include "fetch_abi.h"
22  
23 /* The versions whose members this dist actually calls.
24 *
25 * These are compared with >=, never ==, and never against the installed
26 * header's own constant. The table is append-only, so a provider newer
27 * than this dist is always safe; an equality check would turn every
28 * append into a breaking change for a consumer already shipped. And
29 * comparing against the installed FRX_ABI_VERSION / JWS_ABI_VERSION
30 * would mean that merely compiling against a newer provider raised the
31 * runtime floor of code that touches nothing new in it.
32 *
33 * They are named constants rather than literals at the call sites so
34 * that these numbers and the floors in Makefile.PL are two statements of
35 * one fact, and can be checked against each other:
36 *
37 * PSAML_FRX_NEED 2 parse, root, kind, ns, local, attr_value, find,
38 * by_id, text, c14n, doc_free, and version 2's SV
39 * bridge: doc_to_sv, doc_from_sv, node_from_sv,
40 * node_to_sv. The bridge is what lets Response,
41 * Signature and IdP hand a document or a verified
42 * node to Perl, which is what makes them usable
43 * with no application booted - and `punk saml
44 * verify` against a saved Response is the reason
45 * that requirement exists. File::Raw::XML 0.03 is
46 * the first release with it; Punk 0.46 already
47 * requires that release for the same four entries.
48 * PSAML_JWS_NEED 3 verify, sign, sha256, hmac_sha256, ct_eq,
49 * random_bytes, key_from_pem, key_from_x509_der
50 * PSAML_FETCH_NEED 1 request
51 *
52 * Raise one only when a member from a later version is first called, and
53 * raise the matching Makefile.PL floor in the same commit. */
54 #define PSAML_FRX_NEED 2
55 #define PSAML_JWS_NEED 3
56 #define PSAML_FETCH_NEED 1
57  
58 /* A RESOLVER RUNS PERL. Each one below calls eval_pv for the require and
59 * call_pv for the provider's _abi_ptr, and Perl code reallocates the
60 * argument stack. So a resolver must never be called between an EXTEND
61 * and its matching PUSH, and never with a local SP held across it: the
62 * SP is stale the moment the call returns, and pushing through it writes
63 * into freed memory. Resolve into a local first, SPAGAIN, then push.
64 *
65 * This is only a hazard on the first call, since each resolver caches.
66 * That is what makes it worth writing down: it will not reproduce on the
67 * second run of the same process, and a test that resolves before the
68 * code under test will hide it entirely. */
69  
70 static const frx_abi *PSAML_FRX = NULL;
71 static const jws_abi *PSAML_JWS = NULL;
72 static const fetch_abi *PSAML_FETCH = NULL;
73  
74 26 static IV psaml_call_abi_ptr(pTHX_ const char *require_stmt, const char *fn) {
75 26 dSP;
76 int count;
77 26 IV p = 0;
78 26 eval_pv(require_stmt, FALSE);
79 26 SPAGAIN;
80 26 ▶ if (SvTRUE(ERRSV)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) return 0; 26 0 26
if (SvTRUE(ERRSV)) return 0; 0 26 26
81 26 ▶ ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK;
Branch: 1 branch
BranchTrueFalseTotal
ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; 0 26 26
82 26 count = call_pv(fn, G_SCALAR | G_EVAL);
83 26 SPAGAIN;
84 26 ▶ if (!SvTRUE(ERRSV) && count > 0) p = POPi;
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 26 0 26
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 26 0 26
if (!SvTRUE(ERRSV) && count > 0) p = POPi; 26 0 26
85 0 ▶ else if (count > 0) (void)POPs;
Branch: 1 branch
BranchTrueFalseTotal
else if (count > 0) (void)POPs; 0 0 0
86 26 ▶ PUTBACK; FREETMPS; LEAVE;
Branch: 1 branch
BranchTrueFalseTotal
PUTBACK; FREETMPS; LEAVE; 26 0 26
87 26 return p;
88 }
89  
90 9828 static const frx_abi *psaml_frx(pTHX) {
91 9828 ▶ if (!PSAML_FRX) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PSAML_FRX) { 12 9816 9828
92 12 IV p = psaml_call_abi_ptr(aTHX_ "require File::Raw::XML;",
93 "File::Raw::XML::_abi_ptr");
94 12 ▶ const frx_abi *a = p ? INT2PTR(const frx_abi *, p) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const frx_abi *a = p ? INT2PTR(const frx_abi *, p) : NULL; 12 0 12
95 12 ▶ if (a && a->abi_version >= PSAML_FRX_NEED) PSAML_FRX = a;
Branch: 2 branches
BranchTrueFalseTotal
if (a && a->abi_version >= PSAML_FRX_NEED) PSAML_FRX = a; 12 0 12
if (a && a->abi_version >= PSAML_FRX_NEED) PSAML_FRX = a; 12 0 12
96 }
97 9828 ▶ if (!PSAML_FRX)
Branch: 1 branch
BranchTrueFalseTotal
if (!PSAML_FRX) 0 9828 9828
98 0 croak("Punk::SAML: File::Raw::XML with a compatible C ABI is required "
99 "(frx_abi version %d or newer)", PSAML_FRX_NEED);
100 9828 return PSAML_FRX;
101 }
102  
103 1082 static const jws_abi *psaml_jws(pTHX) {
104 1082 ▶ if (!PSAML_JWS) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PSAML_JWS) { 13 1069 1082
105 13 IV p = psaml_call_abi_ptr(aTHX_ "require Crypt::JWS;",
106 "Crypt::JWS::_abi_ptr");
107 13 ▶ const jws_abi *a = p ? INT2PTR(const jws_abi *, p) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const jws_abi *a = p ? INT2PTR(const jws_abi *, p) : NULL; 13 0 13
108 13 ▶ if (a && a->version >= PSAML_JWS_NEED) PSAML_JWS = a;
Branch: 2 branches
BranchTrueFalseTotal
if (a && a->version >= PSAML_JWS_NEED) PSAML_JWS = a; 13 0 13
if (a && a->version >= PSAML_JWS_NEED) PSAML_JWS = a; 13 0 13
109 }
110 1082 ▶ if (!PSAML_JWS)
Branch: 1 branch
BranchTrueFalseTotal
if (!PSAML_JWS) 0 1082 1082
111 0 croak("Punk::SAML: Crypt::JWS with a compatible C ABI is required "
112 "(jws_abi version %d or newer, for key_from_x509_der)",
113 PSAML_JWS_NEED);
114 1082 return PSAML_JWS;
115 }
116  
117 2 static const fetch_abi *psaml_fetch(pTHX) {
118 2 ▶ if (!PSAML_FETCH) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PSAML_FETCH) { 1 1 2
119 1 IV p = psaml_call_abi_ptr(aTHX_ "require Fetch;", "Fetch::_abi_ptr");
120 1 ▶ const fetch_abi *a = p ? INT2PTR(const fetch_abi *, p) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const fetch_abi *a = p ? INT2PTR(const fetch_abi *, p) : NULL; 1 0 1
121 1 ▶ if (a && a->abi_version >= PSAML_FETCH_NEED) PSAML_FETCH = a;
Branch: 2 branches
BranchTrueFalseTotal
if (a && a->abi_version >= PSAML_FETCH_NEED) PSAML_FETCH = a; 1 0 1
if (a && a->abi_version >= PSAML_FETCH_NEED) PSAML_FETCH = a; 1 0 1
122 }
123 2 ▶ if (!PSAML_FETCH)
Branch: 1 branch
BranchTrueFalseTotal
if (!PSAML_FETCH) 0 2 2
124 0 croak("Punk::SAML: Fetch with a compatible C ABI is required "
125 "(fetch_abi version %d or newer)", PSAML_FETCH_NEED);
126 2 return PSAML_FETCH;
127 }
128  
129 #endif /* PSAML_ABI_H */
« include/psaml/psaml_signature.h ↑ Summary PSAML.c »