xs/password.xs

filter: Statementstmt 91.1% 41 / 45 Branchbran 63.2% 43 / 68 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.3% 84 / 113 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_xml.h ↑ Summary include/punk/punk_wshandshake.h »
1 MODULE = Punk PACKAGE = Punk::Auth::Password
2  
3 PROTOTYPES: DISABLE
4  
5 # Password hashing (punk_password.h): PBKDF2-HMAC-SHA256 over the dist's own
6 # SHA-256, in the MaatSite::Password stored format. Callable as functions or
7 # as class methods - a leading 'Punk::Auth::Password' invocant is skipped, so
8 # migrating code written against the class-method style keeps working.
9  
10 # The iteration default: an explicit argument wins, then the localizable
11 # our $ITERATIONS in Punk/Auth/Password.pm, then the built-in 60_000.
12 SV *
13 hash(...)
14 CODE:
15 {
16 21 int i = 0;
17 SV *plain;
18 21 U32 iterations = 0;
19 STRLEN pl;
20 const unsigned char *p;
21 21 ▶ if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password"))
Branch: 3 branches
BranchTrueFalseTotal
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 21 0 21
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 20 1 21
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 0 20 20
22 0 i++;
23 21 ▶ if (items <= i || !SvOK(ST(i)))
Branch: 2 branches
BranchTrueFalseTotal
if (items <= i || !SvOK(ST(i))) 21 0 21
if (items <= i || !SvOK(ST(i))) 1 20 21
24 1 croak("Punk::Auth::Password: hash needs a password");
25 20 plain = ST(i);
26 20 ▶ if (items > i + 1 && SvOK(ST(i + 1))) {
Branch: 2 branches
BranchTrueFalseTotal
if (items > i + 1 && SvOK(ST(i + 1))) { 4 16 20
if (items > i + 1 && SvOK(ST(i + 1))) { 4 0 4
27 4 IV want = SvIV(ST(i + 1));
28 4 ▶ if (want <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (want <= 0) 1 3 4
29 1 croak("Punk::Auth::Password: iterations must be positive");
30 3 iterations = (U32)want;
31 }
32 else {
33 16 SV *itsv = get_sv("Punk::Auth::Password::ITERATIONS", 0);
34 16 ▶ if (itsv && SvOK(itsv) && SvIV(itsv) > 0)
Branch: 3 branches
BranchTrueFalseTotal
if (itsv && SvOK(itsv) && SvIV(itsv) > 0) 16 0 16
if (itsv && SvOK(itsv) && SvIV(itsv) > 0) 16 0 16
if (itsv && SvOK(itsv) && SvIV(itsv) > 0) 16 0 16
35 16 iterations = (U32)SvIV(itsv);
36 }
37 19 p = (const unsigned char *)SvPV(plain, pl);
38 19 RETVAL = pwd_hash(aTHX_ p, pl, iterations);
39 }
40 OUTPUT:
41 RETVAL
42  
43 IV
44 verify(...)
45 CODE:
46 {
47 15 int i = 0;
48 STRLEN pl, sl;
49 const unsigned char *p;
50 const char *s;
51 15 ▶ if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password"))
Branch: 3 branches
BranchTrueFalseTotal
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 15 0 15
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 15 0 15
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 1 14 15
52 1 i++;
53 15 ▶ if (items <= i + 1 || !SvOK(ST(i)) || !SvOK(ST(i + 1)))
Branch: 3 branches
BranchTrueFalseTotal
if (items <= i + 1 || !SvOK(ST(i)) || !SvOK(ST(i + 1))) 15 0 15
if (items <= i + 1 || !SvOK(ST(i)) || !SvOK(ST(i + 1))) 15 0 15
if (items <= i + 1 || !SvOK(ST(i)) || !SvOK(ST(i + 1))) 1 14 15
54 1 RETVAL = 0;
55 else {
56 14 p = (const unsigned char *)SvPV(ST(i), pl);
57 14 ▶ s = SvPV(ST(i + 1), sl);
Branch: 1 branch
BranchTrueFalseTotal
s = SvPV(ST(i + 1), sl); 14 0 14
58 14 RETVAL = pwd_verify(aTHX_ p, pl, s, sl);
59 }
60 }
61 OUTPUT:
62 RETVAL
63  
64 IV
65 needs_rehash(...)
66 CODE:
67 {
68 7 int i = 0;
69 7 U32 current = 0;
70 STRLEN sl;
71 const char *s;
72 SV *itsv;
73 7 ▶ if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password"))
Branch: 3 branches
BranchTrueFalseTotal
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 7 0 7
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 6 1 7
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 0 6 6
74 0 i++;
75 7 itsv = get_sv("Punk::Auth::Password::ITERATIONS", 0);
76 7 ▶ if (itsv && SvOK(itsv) && SvIV(itsv) > 0) current = (U32)SvIV(itsv);
Branch: 3 branches
BranchTrueFalseTotal
if (itsv && SvOK(itsv) && SvIV(itsv) > 0) current = (U32)SvIV(itsv); 7 0 7
if (itsv && SvOK(itsv) && SvIV(itsv) > 0) current = (U32)SvIV(itsv); 7 0 7
if (itsv && SvOK(itsv) && SvIV(itsv) > 0) current = (U32)SvIV(itsv); 7 0 7
77 7 ▶ if (items > i + 1 && SvOK(ST(i + 1)) && SvIV(ST(i + 1)) > 0)
Branch: 3 branches
BranchTrueFalseTotal
if (items > i + 1 && SvOK(ST(i + 1)) && SvIV(ST(i + 1)) > 0) 1 6 7
if (items > i + 1 && SvOK(ST(i + 1)) && SvIV(ST(i + 1)) > 0) 1 0 1
if (items > i + 1 && SvOK(ST(i + 1)) && SvIV(ST(i + 1)) > 0) 1 0 1
78 1 current = (U32)SvIV(ST(i + 1));
79 7 ▶ if (items <= i || !SvOK(ST(i)))
Branch: 2 branches
BranchTrueFalseTotal
if (items <= i || !SvOK(ST(i))) 7 0 7
if (items <= i || !SvOK(ST(i))) 1 6 7
80 1 RETVAL = 1; /* no hash at all: rehash */
81 else {
82 6 s = SvPV(ST(i), sl);
83 6 RETVAL = pwd_needs_rehash(aTHX_ s, sl, current);
84 }
85 }
86 OUTPUT:
87 RETVAL
88  
89 SV *
90 token(...)
91 CODE:
92 PERL_UNUSED_VAR(items);
93 2 RETVAL = pwd_token(aTHX);
94 OUTPUT:
95 RETVAL
96  
97 SV *
98 token_digest(...)
99 CODE:
100 {
101 6 int i = 0;
102 STRLEN tl;
103 const unsigned char *t;
104 6 ▶ if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password"))
Branch: 3 branches
BranchTrueFalseTotal
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 6 0 6
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 6 0 6
if (items > i && SvPOK(ST(i)) && sv_derived_from(ST(i), "Punk::Auth::Password")) 0 6 6
105 0 i++;
106 6 ▶ if (items <= i || !SvOK(ST(i)))
Branch: 2 branches
BranchTrueFalseTotal
if (items <= i || !SvOK(ST(i))) 6 0 6
if (items <= i || !SvOK(ST(i))) 0 6 6
107 0 croak("Punk::Auth::Password: token_digest needs a token");
108 6 t = (const unsigned char *)SvPV(ST(i), tl);
109 6 RETVAL = pwd_token_digest(aTHX_ t, tl);
110 }
111 OUTPUT:
112 RETVAL
« include/punk/punk_xml.h ↑ Summary include/punk/punk_wshandshake.h »