xs/services.xs

filter: Statementstmt 100% 45 / 45 Branchbran 65.9% 29 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 83.1% 74 / 89 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/arch/Crypt/Symmetric/Primitives/Install/Files.pm »
1 SV *
2 random_bytes(len)
3 SV *len
4 PREINIT:
5 uint32_t want;
6 int code;
7 char *p;
8 CODE:
9 425 want = number_between(aTHX_ "random_bytes", "a length", settled(aTHX_ len), 0, 16 * 1024 * 1024);
10 404 ▶ RETVAL = newSV(want ? want : 1);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSV(want ? want : 1); 397 7 404
11 404 SvPOK_only(RETVAL);
12 404 p = SvPVX(RETVAL);
13 /* A pattern first: a fill that never happened must not pass for one. */
14 404 memset(p, 0xA5, want);
15 404 code = symprim_random(p, want);
16 404 ▶ if (code != SYMPRIM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (code != SYMPRIM_OK) { 5 399 404
17 5 SvREFCNT_dec(RETVAL);
18 5 croak("%s", symprim_error_message(code));
19 }
20 399 p[want] = '\0';
21 399 SvCUR_set(RETVAL, want);
22 OUTPUT:
23 RETVAL
24  
25 const char *
26 _random_source()
27 CODE:
28 2 RETVAL = symprim_random_source();
29 OUTPUT:
30 RETVAL
31  
32 void
33 _random_fails(on)
34 bool on
35 CODE:
36 14 ▶ symprim_set_random(on ? failing_random : NULL);
Branch: 1 branch
BranchTrueFalseTotal
symprim_set_random(on ? failing_random : NULL); 5 9 14
37  
38 SV *
39 equal(a, b)
40 SV *a
41 SV *b
42 PREINIT:
43 STRLEN alen, blen;
44 const uint8_t *ap, *bp;
45 CODE:
46 314 a = bytes_of(aTHX_ a);
47 311 b = bytes_of(aTHX_ b);
48 309 ap = bytes_at(aTHX_ a, &alen);
49 309 bp = bytes_at(aTHX_ b, &blen);
50 /* A length is not a secret, so two lengths are answered at once. Two of
51 * one length are read whole, wherever they differ. */
52 309 ▶ RETVAL = alen == blen && symprim_equal(ap, bp, alen) ? &PL_sv_yes : &PL_sv_no;
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = alen == blen && symprim_equal(ap, bp, alen) ? &PL_sv_yes : &PL_sv_no; 301 8 309
RETVAL = alen == blen && symprim_equal(ap, bp, alen) ? &PL_sv_yes : &PL_sv_no; 21 280 301
53 309 SvREFCNT_inc_simple_void_NN(RETVAL);
54 OUTPUT:
55 RETVAL
56  
57 void
58 _wipe(buffer)
59 SV *buffer
60 PREINIT:
61 STRLEN len;
62 char *p;
63 CODE:
64 /* The one door that writes to what it is given. The string is wiped
65 * where it lies, in whatever form it is held: nothing is converted
66 * first, since a conversion that failed would leave it as it was, and
67 * one that worked would leave the longer form behind the shorter. All
68 * that the scalar holds is wiped and not only the part in use: a string
69 * that was cut short still has the rest after its end, and one that was
70 * cut at the front has it before its start. What is not a string is
71 * refused. */
72 9 SvGETMAGIC(buffer);
73 /* The private flag: before perl 5.18 it is the only one that a scalar
74 * whose value was just fetched shows. */
75 9 ▶ if (!SvPOKp(buffer))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvPOKp(buffer)) 2 7 9
76 2 croak("_wipe takes a string");
77 7 p = SvPV_force_nomg(buffer, len);
78 7 ▶ if (SvOOK(buffer)) {
Branch: 4 branches
BranchTrueFalseTotal
if (SvOOK(buffer)) { 0 7 7
if (SvOOK(buffer)) { 0 0 0
if (SvOOK(buffer)) { 0 0 0
if (SvOOK(buffer)) { 1 6 7
79 1 ▶ SvOOK_off(buffer);
Branch: 4 branches
BranchTrueFalseTotal
SvOOK_off(buffer); 0 1 1
SvOOK_off(buffer); 0 0 0
SvOOK_off(buffer); 0 0 0
SvOOK_off(buffer); 1 0 1
80 1 p = SvPVX(buffer);
81 }
82 7 symprim_wipe(p, SvLEN(buffer) > len ? SvLEN(buffer) : len);
83 7 ▶ SvSETMAGIC(buffer);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(buffer); 1 6 7
84  
85 SV *
86 _lock_memory(len)
87 SV *len
88 PREINIT:
89 uint32_t want;
90 void *p;
91 int code;
92 CODE:
93 20 want = number_between(aTHX_ "_lock_memory", "a length", settled(aTHX_ len), 0, 16 * 1024 * 1024);
94 11 ▶ p = symprim_malloc(want ? want : 1);
Branch: 1 branch
BranchTrueFalseTotal
p = symprim_malloc(want ? want : 1); 10 1 11
95 11 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 1 10 11
96 1 croak("%s", symprim_error_message(SYMPRIM_E_MEMORY));
97 10 code = symprim_lock_memory(p, want);
98 /* Let go whether or not it was had: letting go what was never held does
99 * nothing. */
100 10 symprim_unlock_memory(p, want);
101 10 symprim_free(p);
102 10 ▶ RETVAL = code == SYMPRIM_OK ? &PL_sv_yes : &PL_sv_no; /* # uncoverable condition right class:ignore_covered_err */
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = code == SYMPRIM_OK ? &PL_sv_yes : &PL_sv_no; /* # uncoverable condition right class:ignore_covered_err */ 10 0 10
103 10 SvREFCNT_inc_simple_void_NN(RETVAL);
104 OUTPUT:
105 RETVAL
106  
107 void
108 _errors()
109 PREINIT:
110 2 size_t i, count = sizeof error_names / sizeof error_names[0];
111 const char *said;
112 PPCODE:
113 2 ▶ EXTEND(SP, (SSize_t)(2 * count));
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, (SSize_t)(2 * count)); 2 0 2
EXTEND(SP, (SSize_t)(2 * count)); 0 2 2
114 14 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 12 2 14
115 12 said = symprim_error_message(error_names[i].code);
116 12 mPUSHp(error_names[i].name, strlen(error_names[i].name));
117 12 mPUSHp(said, strlen(said));
118 }
119 2 XSRETURN((int)(2 * count));
120  
121 IV
122 _error_count()
123 CODE:
124 4 ▶ RETVAL = SYMPRIM_E_COUNT;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = SYMPRIM_E_COUNT; 0 4 4
125 OUTPUT:
126 RETVAL
↑ Summary blib/arch/Crypt/Symmetric/Primitives/Install/Files.pm »