blib/lib/Zuzu/Module/Secure.pm

filter: Statementstmt 16.1% 168 / 1040 Branchbran 2.0% 9 / 450 Conditioncond 1.3% 4 / 301 MC/DCmcdc 0.0% 0 / 169 Subroutinesub 17.3% 33 / 190 Podpod 0.0% 0 / 1 totaltotal 9.9% 214 / 2151 CC 337 SCAR 50.4
CC
337
Cov
10%
_parse_password_hash
1406.0
_has_capability
306.0
_password_hash_needs_rehash
306.0
CRAP 154.6
« blib/script/zuzu-highlight.pl ↑ Summary blib/lib/Zuzu/Runtime.pm »
1 package Zuzu::Module::Secure;
2  
3 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 our $VERSION = '0.007002';
6  
7 3 ▶use Crypt::AuthEnc::GCM qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 gcm_decrypt_verify
9 gcm_encrypt_authenticate
10 3 );
11 3 ▶use Crypt::AuthEnc::ChaCha20Poly1305 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 chacha20poly1305_decrypt_verify
13 chacha20poly1305_encrypt_authenticate
14 3 );
15 3 ▶use Crypt::KeyDerivation qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
16 argon2_pbkdf
17 pbkdf2
18 scrypt_pbkdf
19 3 );
20 3 ▶use Crypt::PK::Ed25519;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Crypt::PK::ECC;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Crypt::PK::X25519;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Crypt::OpenSSL::PKCS12;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Crypt::OpenSSL::X509;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Crypt::URandom qw( urandom );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Digest::SHA qw( hmac_sha256 sha256 sha384 sha512 );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use Encode qw( encode_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use MIME::Base64 qw( decode_base64 encode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use Net::SSLeay ();
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ▶use DateTime::Lite ();
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 3 ▶use Zuzu::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use Zuzu::Util::NativeHelpers qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
34 native_class
35 native_function
36 native_object
37 3 );
38 3 ▶use Zuzu::Value::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use Zuzu::Value::BinaryString;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use Zuzu::Value::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 3 ▶use Zuzu::Value::Dict;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 3 ▶use Scalar::Util qw( blessed looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 3 my @BASE64URL = split //,
45 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
46 3 my $HOST = 'perl';
47 3 my %RANDOM_CAPABILITIES = map { $_ => 1 } qw( bytes token int );
48 3 my %PASSWORD_HASH_CAPABILITIES = map { $_ => 1 } qw(
49 argon2id
50 crypt
51 pbkdf2-sha256
52 scrypt
53 );
54 3 my %KDF_CAPABILITIES = map { $_ => 1 } qw( hkdf-sha256 );
55 3 my %CIPHER_CAPABILITIES = map { $_ => 1 } qw(
56 aes-128-gcm
57 aes-192-gcm
58 aes-256-gcm
59 chacha20-poly1305
60 );
61 3 my %KEY_AGREEMENT_CAPABILITIES = map { $_ => 1 } qw( x25519 );
62 3 my %CERTIFICATE_CAPABILITIES = map { $_ => 1 } qw(
63 parse-x509
64 parse-x509-der
65 fingerprint-sha256
66 fingerprint-sha384
67 fingerprint-sha512
68 public-key
69 verify-chain
70 );
71 3 my %CERTIFICATE_TIME_MONTH = (
72 Jan => 1,
73 Feb => 2,
74 Mar => 3,
75 Apr => 4,
76 May => 5,
77 Jun => 6,
78 Jul => 7,
79 Aug => 8,
80 Sep => 9,
81 Oct => 10,
82 Nov => 11,
83 Dec => 12,
84 );
85 3 my %TLS_IDENTITY_CAPABILITIES = map { $_ => 1 } qw( pem pkcs12 );
86 3 my %SIGNING_CAPABILITIES = map { $_ => 1 } qw(
87 ed25519
88 ecdsa-p256-sha256
89 ecdsa-p384-sha384
90 ecdsa-p521-sha512
91 );
92 3 my %SIGNING_ALGORITHMS = (
93 'ed25519' => {
94 type => 'ed25519',
95 private_length => 32,
96 public_length => 32,
97 },
98 'ecdsa-p256-sha256' => {
99 type => 'ecdsa',
100 curve => 'prime256v1',
101 hash => 'SHA256',
102 private_length => 32,
103 public_length => 65,
104 },
105 'ecdsa-p384-sha384' => {
106 type => 'ecdsa',
107 curve => 'secp384r1',
108 hash => 'SHA384',
109 private_length => 48,
110 public_length => 97,
111 },
112 'ecdsa-p521-sha512' => {
113 type => 'ecdsa',
114 curve => 'secp521r1',
115 hash => 'SHA512',
116 private_length => 66,
117 public_length => 133,
118 },
119 );
120 3 my $DEFAULT_PASSWORD_HASH_ALGORITHM = 'pbkdf2-sha256';
121 3 my $MAX_SAFE_INT = 9007199254740992;
122 3 my $RANDOM_INT_SPACE = 72057594037927936;
123 3 my $HKDF_SHA256_HASH_LENGTH = 32;
124 3 my $HKDF_SHA256_MAX_LENGTH = 255 * $HKDF_SHA256_HASH_LENGTH;
125 3 my %CIPHER_ALGORITHMS = (
126 'aes-128-gcm' => {
127 key_length => 16,
128 nonce_length => 12,
129 tag_length => 16,
130 gcm_cipher => 'AES',
131 },
132 'aes-192-gcm' => {
133 key_length => 24,
134 nonce_length => 12,
135 tag_length => 16,
136 gcm_cipher => 'AES',
137 },
138 'aes-256-gcm' => {
139 key_length => 32,
140 nonce_length => 12,
141 tag_length => 16,
142 gcm_cipher => 'AES',
143 },
144 'chacha20-poly1305' => {
145 key_length => 32,
146 nonce_length => 12,
147 tag_length => 16,
148 },
149 );
150 3 my $PASSWORD_HASH_SALT_LENGTH = 16;
151 3 my $PASSWORD_HASH_LENGTH = 32;
152 3 my $PBKDF2_SHA256_ITERATIONS = 600_000;
153 3 my $ARGON2ID_MEMORY = 19_456;
154 3 my $ARGON2ID_ITERATIONS = 2;
155 3 my $ARGON2ID_PARALLELISM = 1;
156 3 my $SCRYPT_LOG_N = 17;
157 3 my $SCRYPT_R = 8;
158 3 my $SCRYPT_P = 1;
159  
160 0 ▶sub _true {
Subroutine _true: not called CC=1 SCAR=6.9
161 0 return Zuzu::Value::Boolean->new( value => 1 );
162 }
163  
164 0 ▶sub _false {
Subroutine _false: not called CC=1 SCAR=6.9
165 0 return Zuzu::Value::Boolean->new( value => 0 );
166 }
167  
168 0 ▶sub _empty_array {
Subroutine _empty_array: not called CC=1 SCAR=6.9
169 0 return Zuzu::Value::Array->new( items => [] );
170 }
171  
172 0 ▶sub _array {
Subroutine _array: not called CC=1 SCAR=6.9
173 0 return Zuzu::Value::Array->new( items => [ @_ ] );
174 }
175  
176 0 ▶sub _error {
Subroutine _error: not called CC=1 SCAR=6.9
177 0 my ( $message ) = @_;
178  
179 0 die Zuzu::Error->new_runtime(
180 message => $message,
181 file => '<std/secure>',
182 line => 0,
183 );
184 }
185  
186 0 ▶sub _capabilities {
Subroutine _capabilities: not called CC=1 SCAR=6.9
187 0 return Zuzu::Value::Dict->new(
188 map => {
189 host => $HOST,
190 random => _true(),
191 password_hash => _array(
192 sort keys %PASSWORD_HASH_CAPABILITIES,
193 ),
194 kdf => _array( sort keys %KDF_CAPABILITIES ),
195 cipher => _array( sort keys %CIPHER_CAPABILITIES ),
196 key_agreement => _array(
197 sort keys %KEY_AGREEMENT_CAPABILITIES,
198 ),
199 signing => _array( sort keys %SIGNING_CAPABILITIES ),
200 certificate => _array( sort keys %CERTIFICATE_CAPABILITIES ),
201 tls_identity => _array( sort keys %TLS_IDENTITY_CAPABILITIES ),
202 async_required => Zuzu::Value::Dict->new(
203 map => {
204 cipher => _false(),
205 kdf => _false(),
206 password_hash => _false(),
207 signing => _false(),
208 key_agreement => _false(),
209 },
210 ),
211 },
212 );
213 }
214  
215 0 ▶sub _capability_part {
Subroutine _capability_part: not called CC=2 SCAR=17.9
216 0 my ( $value ) = @_;
217  
218 0 ▶ return defined $value ? "$value" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
219 }
220  
221 0 ▶sub _has_capability {
Subroutine _has_capability: not called CC=17 SCAR=57.2
222 0 my ( $area, $name ) = @_;
223  
224 0 $area = _capability_part($area);
225 0 $name = _capability_part($name);
226  
227 0 ▶ return 1 if $area eq 'random' and $RANDOM_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "random" and $RANDOM_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "random" and $RANDOM_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "random" and $RANDOM_CAPABILITIES{$name}
$area eq "random" $RANDOM_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "random"B= $RANDOM_CAPABILITIES{$name}
ABresult
0X0
100
111
228 return 1
229 if $area eq 'password_hash'
230 0 ▶ and $PASSWORD_HASH_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "password_hash" and $PASSWORD_HASH_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "password_hash" and $PASSWORD_HASH_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "password_hash" and $PASSWORD_HASH_CAPABILITIES{$name}
$area eq "password_hash" $PASSWORD_HASH_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "password_hash"B= $PASSWORD_HASH_CAPABILITIES{$name}
ABresult
0X0
100
111
231 0 ▶ return 1 if $area eq 'kdf' and $KDF_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "kdf" and $KDF_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "kdf" and $KDF_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "kdf" and $KDF_CAPABILITIES{$name}
$area eq "kdf" $KDF_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "kdf"B= $KDF_CAPABILITIES{$name}
ABresult
0X0
100
111
232 0 ▶ return 1 if $area eq 'cipher' and $CIPHER_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "cipher" and $CIPHER_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "cipher" and $CIPHER_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "cipher" and $CIPHER_CAPABILITIES{$name}
$area eq "cipher" $CIPHER_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "cipher"B= $CIPHER_CAPABILITIES{$name}
ABresult
0X0
100
111
233 return 1
234 if $area eq 'key_agreement'
235 0 ▶ and $KEY_AGREEMENT_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "key_agreement" and $KEY_AGREEMENT_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "key_agreement" and $KEY_AGREEMENT_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "key_agreement" and $KEY_AGREEMENT_CAPABILITIES{$name}
$area eq "key_agreement" $KEY_AGREEMENT_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "key_agreement"B= $KEY_AGREEMENT_CAPABILITIES{$name}
ABresult
0X0
100
111
236 0 ▶ return 1 if $area eq 'signing' and $SIGNING_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "signing" and $SIGNING_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "signing" and $SIGNING_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "signing" and $SIGNING_CAPABILITIES{$name}
$area eq "signing" $SIGNING_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "signing"B= $SIGNING_CAPABILITIES{$name}
ABresult
0X0
100
111
237 return 1
238 if $area eq 'certificate'
239 0 ▶ and $CERTIFICATE_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "certificate" and $CERTIFICATE_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "certificate" and $CERTIFICATE_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "certificate" and $CERTIFICATE_CAPABILITIES{$name}
$area eq "certificate" $CERTIFICATE_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "certificate"B= $CERTIFICATE_CAPABILITIES{$name}
ABresult
0X0
100
111
240 return 1
241 if $area eq 'tls_identity'
242 0 ▶ and $TLS_IDENTITY_CAPABILITIES{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $area eq "tls_identity" and $TLS_IDENTITY_CAPABILITIES{$name} 0 0 0
Condition0%0/3
$area eq "tls_identity" and $TLS_IDENTITY_CAPABILITIES{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
$area eq "tls_identity" and $TLS_IDENTITY_CAPABILITIES{$name}
$area eq "tls_identity" $TLS_IDENTITY_CAPABILITIES{$name}
Truth table0%0/3
A and B
A= $area eq "tls_identity"B= $TLS_IDENTITY_CAPABILITIES{$name}
ABresult
0X0
100
111
243 0 return 0;
244 }
245  
246 0 ▶sub _require_capability {
Subroutine _require_capability: not called CC=2 SCAR=17.9
247 0 my ( $area, $name ) = @_;
248  
249 0 $area = _capability_part($area);
250 0 $name = _capability_part($name);
251  
252 0 ▶ return _true() if _has_capability( $area, $name );
Branch: 1 branch
BranchTrueFalseTotal
if _has_capability($area, $name) 0 0 0
253  
254 0 _error(
255 "Secure capability '$area/$name' is not available on host '$HOST'",
256 );
257 }
258  
259 0 ▶sub _non_negative_integer {
Subroutine _non_negative_integer: not called CC=6 SCAR=37.4
260 0 my ( $value, $label ) = @_;
261  
262 0 ▶ _error( "$label expects a non-negative integer" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and &looks_like_number($value) 0 0 0
Condition0%0/3
defined $value and &looks_like_number($value)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and &looks_like_number($value)
defined $value &looks_like_number($value)
Truth table0%0/3
A and B
A= defined $valueB= &looks_like_number($value)
ABresult
0X0
100
111
263 if not defined $value or not looks_like_number($value);
264  
265 0 ▶ my $number = 0 + ( defined $value ? $value : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
266 0 ▶ _error( "$label expects a non-negative integer" )
Branch: 1 branch
BranchTrueFalseTotal
if $number < 0 or $number != int $number 0 0 0
Condition0%0/3
$number < 0 or $number != int $number
l!l&&r!l&&!r
000
MC/DC0%0/2
$number < 0 or $number != int $number
$number < 0 $number != int $number
Truth table0%0/3
A or B
A= $number < 0B= $number != int $number
ABresult
1X1
011
000
267 if $number < 0 or $number != int($number);
268  
269 0 return int($number);
270 }
271  
272 0 ▶sub _positive_integer {
Subroutine _positive_integer: not called CC=7 SCAR=40.3
273 0 my ( $value, $label ) = @_;
274  
275 0 ▶ _error( "$label expects a positive integer" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and &looks_like_number($value) 0 0 0
Condition0%0/3
defined $value and &looks_like_number($value)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and &looks_like_number($value)
defined $value &looks_like_number($value)
Truth table0%0/3
A and B
A= defined $valueB= &looks_like_number($value)
ABresult
0X0
100
111
276 if not defined $value or not looks_like_number($value);
277  
278 0 ▶ my $number = 0 + ( defined $value ? $value : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
279 0 ▶ _error( "$label expects a positive integer" )
Branch: 1 branch
BranchTrueFalseTotal
if $number <= 0 or $number != int $number 0 0 0
Condition0%0/3
$number <= 0 or $number != int $number
l!l&&r!l&&!r
000
MC/DC0%0/2
$number <= 0 or $number != int $number
$number <= 0 $number != int $number
Truth table0%0/3
A or B
A= $number <= 0B= $number != int $number
ABresult
1X1
011
000
280 if $number <= 0 or $number != int($number);
281 0 ▶ _error( "$label maximum is too large" )
Branch: 1 branch
BranchTrueFalseTotal
if $number > $MAX_SAFE_INT 0 0 0
282 if $number > $MAX_SAFE_INT;
283  
284 0 return int($number);
285 }
286  
287 0 ▶sub _hkdf_length {
Subroutine _hkdf_length: not called CC=7 SCAR=40.3
288 0 my ( $value, $label ) = @_;
289  
290 0 ▶ _error( "$label expects length between 0 and $HKDF_SHA256_MAX_LENGTH" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and &looks_like_number($value) 0 0 0
Condition0%0/3
defined $value and &looks_like_number($value)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and &looks_like_number($value)
defined $value &looks_like_number($value)
Truth table0%0/3
A and B
A= defined $valueB= &looks_like_number($value)
ABresult
0X0
100
111
291 if not defined $value or not looks_like_number($value);
292  
293 0 ▶ my $number = 0 + ( defined $value ? $value : 0 );
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 0 0 0
294 0 ▶ _error( "$label expects length between 0 and $HKDF_SHA256_MAX_LENGTH" )
Branch: 1 branch
BranchTrueFalseTotal
if $number < 0 or $number != int $number 0 0 0
Condition0%0/3
$number < 0 or $number != int $number
l!l&&r!l&&!r
000
MC/DC0%0/2
$number < 0 or $number != int $number
$number < 0 $number != int $number
Truth table0%0/3
A or B
A= $number < 0B= $number != int $number
ABresult
1X1
011
000
295 if $number < 0 or $number != int($number);
296 0 ▶ _error( "$label expects length between 0 and $HKDF_SHA256_MAX_LENGTH" )
Branch: 1 branch
BranchTrueFalseTotal
if $number > $HKDF_SHA256_MAX_LENGTH 0 0 0
297 if $number > $HKDF_SHA256_MAX_LENGTH;
298  
299 0 return int($number);
300 }
301  
302 0 ▶sub _type_name {
Subroutine _type_name: not called CC=8 SCAR=42.8
303 0 my ( $value ) = @_;
304  
305 0 ▶ return 'Null' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
306 0 ▶ return 'BinaryString'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString") 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
307 if blessed($value)
308 and $value->isa( 'Zuzu::Value::BinaryString' );
309 0 ▶ return 'Dict'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::Dict") 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Dict")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Dict")
builtin::blessed($value) $value->isa("Zuzu::Value::Dict")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Dict")
ABresult
0X0
100
111
310 if blessed($value)
311 and $value->isa( 'Zuzu::Value::Dict' );
312 0 ▶ return 'Array'
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::Array") 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
builtin::blessed($value) $value->isa("Zuzu::Value::Array")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Array")
ABresult
0X0
100
111
313 if blessed($value)
314 and $value->isa( 'Zuzu::Value::Array' );
315 0 return 'String';
316 }
317  
318 0 ▶sub _binary_bytes {
Subroutine _binary_bytes: not called CC=4 SCAR=30.0
319 0 my ( $value, $label, $arg_name ) = @_;
320  
321 0 ▶ $arg_name //= 'BinaryString';
Condition0%0/2
$arg_name //= "BinaryString"
l!l
00
MC/DC0%0/1
$arg_name //= "BinaryString"
$arg_name
Truth table0%0/2
A
A= $arg_name
Aresult
11
00
322  
323 0 ▶ return $value->bytes
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString") 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
324 if blessed($value)
325 and $value->isa( 'Zuzu::Value::BinaryString' );
326  
327 0 _error( 'TypeException: '
328 . "$label expects $arg_name, got "
329 . _type_name($value) );
330 }
331  
332 0 ▶sub _optional_binary_bytes {
Subroutine _optional_binary_bytes: not called CC=2 SCAR=17.9
333 0 my ( $value, $label, $arg_name ) = @_;
334  
335 0 ▶ return '' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
336 0 return _binary_bytes( $value, $label, $arg_name );
337 }
338  
339 0 ▶sub _dict_map {
Subroutine _dict_map: not called CC=4 SCAR=30.0
340 0 my ( $value, $label, $arg_name ) = @_;
341  
342 0 ▶ $arg_name //= 'Dict';
Condition0%0/2
$arg_name //= "Dict"
l!l
00
MC/DC0%0/1
$arg_name //= "Dict"
$arg_name
Truth table0%0/2
A
A= $arg_name
Aresult
11
00
343  
344 0 ▶ return $value->map
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::Dict") 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Dict")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Dict")
builtin::blessed($value) $value->isa("Zuzu::Value::Dict")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Dict")
ABresult
0X0
100
111
345 if blessed($value)
346 and $value->isa( 'Zuzu::Value::Dict' );
347  
348 0 _error( 'TypeException: '
349 . "$label expects $arg_name, got "
350 . _type_name($value) );
351 }
352  
353 0 ▶sub _optional_dict_map {
Subroutine _optional_dict_map: not called CC=2 SCAR=17.9
354 0 my ( $value, $label, $arg_name ) = @_;
355  
356 0 ▶ return {} if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
357 0 return _dict_map( $value, $label, $arg_name );
358 }
359  
360 1 ▶sub _optional_password_text {
Subroutine _optional_password_text: called CC=2 SCAR=8.1
361 1 my ( $value, $label, $arg_name ) = @_;
362  
363 1 ▶ return '' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 0 1
364 0 return _string_arg( $value, $label, $arg_name );
365 }
366  
367 0 ▶sub _cipher_algorithm {
Subroutine _cipher_algorithm: not called CC=3 SCAR=24.8
368 0 my ( $value, $label ) = @_;
369  
370 0 ▶ $value = 'aes-256-gcm' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
371 _error( "$label cipher algorithm '$value' is not available" )
372 0 ▶ if not $CIPHER_CAPABILITIES{"$value"};
Branch: 1 branch
BranchTrueFalseTotal
unless $CIPHER_CAPABILITIES{"$value"} 0 0 0
373  
374 0 return "$value";
375 }
376  
377 0 ▶sub _cipher_options {
Subroutine _cipher_options: not called CC=3 SCAR=24.8
378 0 my ( $value, $label ) = @_;
379  
380 0 my $options = _optional_dict_map( $value, $label, 'Dict options' );
381 my $algorithm = _cipher_algorithm(
382 $options->{algorithm},
383 $label,
384 0 ▶ ) if defined $options->{algorithm};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options->{"algorithm"} 0 0 0
385 my $aad = _optional_binary_bytes(
386 $options->{aad},
387 0 $label,
388 'BinaryString aad',
389 );
390  
391 0 ▶ return ( $algorithm // 'aes-256-gcm', $aad, defined $options->{algorithm} );
Condition0%0/2
$algorithm // "aes-256-gcm"
l!l
00
MC/DC0%0/1
$algorithm // "aes-256-gcm"
$algorithm
Truth table0%0/2
A
A= $algorithm
Aresult
11
00
392 }
393  
394 0 ▶sub _cipher_meta {
Subroutine _cipher_meta: not called CC=1 SCAR=6.9
395 0 my ( $algorithm, $label ) = @_;
396  
397 0 $algorithm = _cipher_algorithm( $algorithm, $label );
398 0 return $CIPHER_ALGORITHMS{$algorithm};
399 }
400  
401 0 ▶sub _cipher_key {
Subroutine _cipher_key: not called CC=2 SCAR=17.9
402 0 my ( $value, $label, $meta ) = @_;
403  
404 0 my $key = _binary_bytes( $value, $label, 'BinaryString key' );
405 _error( "$label expects a $meta->{key_length}-byte key" )
406 0 ▶ if length($key) != $meta->{key_length};
Branch: 1 branch
BranchTrueFalseTotal
if length $key != $meta->{"key_length"} 0 0 0
407  
408 0 return $key;
409 }
410  
411 0 ▶sub _envelope_bytes {
Subroutine _envelope_bytes: not called CC=3 SCAR=24.8
412 0 my ( $map, $field, $label, $length ) = @_;
413  
414 my $bytes = _binary_bytes(
415 0 $map->{$field},
416 $label,
417 "BinaryString envelope.$field",
418 );
419 0 ▶ _error( "$label expects envelope.$field to be $length bytes" )
Branch: 1 branch
BranchTrueFalseTotal
if defined $length and length $bytes != $length 0 0 0
Condition0%0/3
defined $length and length $bytes != $length
!ll&&!rl&&r
000
MC/DC0%0/2
defined $length and length $bytes != $length
defined $length length $bytes != $length
Truth table0%0/3
A and B
A= defined $lengthB= length $bytes != $length
ABresult
0X0
100
111
420 if defined $length and length($bytes) != $length;
421  
422 0 return $bytes;
423 }
424  
425 0 ▶sub _cipher_envelope {
Subroutine _cipher_envelope: not called CC=3 SCAR=24.8
426 0 my ( $value, $label ) = @_;
427  
428 0 my $map = _dict_map( $value, $label, 'Dict envelope' );
429 _error( "$label expects envelope.version 1" )
430 0 ▶ if not defined $map->{version} or $map->{version} != 1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $map->{"version"} or $map->{"version"} != 1 0 0 0
Condition0%0/3
not defined $map->{"version"} or $map->{"version"} != 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $map->{"version"} or $map->{"version"} != 1
not defined $map->{"version"} $map->{"version"} != 1
Truth table0%0/3
not(A) or B
A= not defined $map->{"version"}B= $map->{"version"} != 1
ABresult
1X1
011
000
431 0 my $algorithm = _cipher_algorithm( $map->{algorithm}, $label );
432 0 my $meta = _cipher_meta( $algorithm, $label );
433  
434 return (
435 $algorithm,
436 _envelope_bytes(
437 $map,
438 'nonce',
439 $label,
440 $meta->{nonce_length},
441 ),
442 _envelope_bytes( $map, 'ciphertext', $label, undef ),
443 0 _envelope_bytes( $map, 'tag', $label, $meta->{tag_length} ),
444 );
445 }
446  
447 0 ▶sub _cipher_envelope_value {
Subroutine _cipher_envelope_value: not called CC=1 SCAR=6.9
448 0 my ( $algorithm, $nonce, $ciphertext, $tag ) = @_;
449  
450 0 return Zuzu::Value::Dict->new(
451 map => {
452 version => 1,
453 algorithm => $algorithm,
454 nonce => Zuzu::Value::BinaryString->new( bytes => $nonce ),
455 ciphertext => Zuzu::Value::BinaryString->new(
456 bytes => $ciphertext,
457 ),
458 tag => Zuzu::Value::BinaryString->new( bytes => $tag ),
459 },
460 );
461 }
462  
463 0 ▶sub _cipher_generate_key {
Subroutine _cipher_generate_key: not called CC=1 SCAR=6.9
464 0 my ( $algorithm ) = @_;
465  
466 0 my $meta = _cipher_meta( $algorithm, 'Cipher.generate_key' );
467 0 return _random_bytes( $meta->{key_length} );
468 }
469  
470 0 ▶sub _cipher_encrypt {
Subroutine _cipher_encrypt: not called CC=3 SCAR=24.8
471 0 my ( $plaintext, $key, $options ) = @_;
472  
473 0 my $label = 'Cipher.encrypt';
474 0 my $bytes = _binary_bytes( $plaintext, $label, 'BinaryString plaintext' );
475 0 my ( $algorithm, $aad ) = _cipher_options( $options, $label );
476 0 my $meta = _cipher_meta( $algorithm, $label );
477 0 $key = _cipher_key( $key, $label, $meta );
478 0 my $nonce = urandom( $meta->{nonce_length} );
479 0 my ( $ciphertext, $tag );
480 0 ▶ if ( exists $meta->{gcm_cipher} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $meta->{'gcm_cipher'}) { } 0 0 0
elsif ($algorithm eq 'chacha20-poly1305') { } 0 0 0
481 ( $ciphertext, $tag ) = gcm_encrypt_authenticate(
482 $meta->{gcm_cipher},
483 0 $key,
484 $nonce,
485 $aad,
486 $bytes,
487 );
488 }
489 elsif ( $algorithm eq 'chacha20-poly1305' ) {
490 0 ( $ciphertext, $tag ) = chacha20poly1305_encrypt_authenticate(
491 $key,
492 $nonce,
493 $aad,
494 $bytes,
495 );
496 }
497  
498 0 return _cipher_envelope_value( $algorithm, $nonce, $ciphertext, $tag );
499 }
500  
501 0 ▶sub _cipher_decrypt {
Subroutine _cipher_decrypt: not called CC=6 SCAR=37.4
502 0 my ( $envelope, $key, $options ) = @_;
503  
504 0 my $label = 'Cipher.decrypt';
505 0 my ( $algorithm, $nonce, $ciphertext, $tag ) = _cipher_envelope(
506 $envelope,
507 $label,
508 );
509 0 my ( $option_algorithm, $aad, $algorithm_supplied ) =
510 _cipher_options( $options, $label );
511 0 ▶ _error( "$label options.algorithm does not match envelope.algorithm" )
Branch: 1 branch
BranchTrueFalseTotal
if $algorithm_supplied and $option_algorithm ne $algorithm 0 0 0
Condition0%0/3
$algorithm_supplied and $option_algorithm ne $algorithm
!ll&&!rl&&r
000
MC/DC0%0/2
$algorithm_supplied and $option_algorithm ne $algorithm
$algorithm_supplied $option_algorithm ne $algorithm
Truth table0%0/3
A and B
A= $algorithm_suppliedB= $option_algorithm ne $algorithm
ABresult
0X0
100
111
512 if $algorithm_supplied and $option_algorithm ne $algorithm;
513 0 my $meta = _cipher_meta( $algorithm, $label );
514 0 $key = _cipher_key( $key, $label, $meta );
515 0 my $plaintext;
516 0 ▶ if ( exists $meta->{gcm_cipher} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $meta->{'gcm_cipher'}) { } 0 0 0
elsif ($algorithm eq 'chacha20-poly1305') { } 0 0 0
517 $plaintext = gcm_decrypt_verify(
518 $meta->{gcm_cipher},
519 0 $key,
520 $nonce,
521 $aad,
522 $ciphertext,
523 $tag,
524 );
525 }
526 elsif ( $algorithm eq 'chacha20-poly1305' ) {
527 0 $plaintext = chacha20poly1305_decrypt_verify(
528 $key,
529 $nonce,
530 $aad,
531 $ciphertext,
532 $tag,
533 );
534 }
535 0 ▶ _error( 'Cipher.decrypt authentication failed' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plaintext 0 0 0
536 if not defined $plaintext;
537  
538 0 return Zuzu::Value::BinaryString->new( bytes => $plaintext );
539 }
540  
541 3 ▶sub _string_arg {
Subroutine _string_arg: called CC=4 SCAR=15.6
542 3 my ( $value, $label, $arg_name ) = @_;
543  
544 3 ▶ $arg_name //= 'String';
Condition50%1/2
$arg_name //= "String"
l!l
30
MC/DC0%0/1
$arg_name //= "String"
$arg_name
Truth table50%1/2
A
A= $arg_name
Aresult
11
00
545 3 ▶ _error( 'TypeException: '
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or builtin::blessed($value) 0 3 3
Condition33%1/3
not defined $value or builtin::blessed($value)
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $value or builtin::blessed($value)
not defined $value builtin::blessed($value)
Truth table33%1/3
not(A) or B
A= not defined $valueB= builtin::blessed($value)
ABresult
1X1
011
000
546 . "$label expects $arg_name, got "
547 . _type_name($value) )
548 if not defined $value or blessed($value);
549  
550 3 return encode_utf8("$value");
551 }
552  
553 0 ▶sub _option_string {
Subroutine _option_string: not called CC=2 SCAR=17.9
554 0 my ( $options, $key, $default ) = @_;
555  
556 0 ▶ return $default if not defined $options->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{$key} 0 0 0
557 0 return "$options->{$key}";
558 }
559  
560 0 ▶sub _option_positive_integer {
Subroutine _option_positive_integer: not called CC=2 SCAR=17.9
561 0 my ( $options, $key, $default, $label ) = @_;
562  
563 0 ▶ return $default if not defined $options->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{$key} 0 0 0
564 0 return _positive_integer( $options->{$key}, "$label option '$key'" );
565 }
566  
567 0 ▶sub _password_hash_algorithm {
Subroutine _password_hash_algorithm: not called CC=2 SCAR=17.9
568 0 my ( $options, $label ) = @_;
569  
570 0 my $algorithm = _option_string(
571 $options,
572 'algorithm',
573 $DEFAULT_PASSWORD_HASH_ALGORITHM,
574 );
575 _error( "$label password hash algorithm '$algorithm' is not available" )
576 0 ▶ if not $PASSWORD_HASH_CAPABILITIES{$algorithm};
Branch: 1 branch
BranchTrueFalseTotal
unless $PASSWORD_HASH_CAPABILITIES{$algorithm} 0 0 0
577  
578 0 return $algorithm;
579 }
580  
581 0 ▶sub _base64url_decode {
Subroutine _base64url_decode: not called CC=4 SCAR=30.0
582 0 my ( $text ) = @_;
583  
584 0 ▶ return undef if not defined $text or $text =~ /[^A-Za-z0-9_-]/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $text or $text =~ /[^A-Za-z0-9_-]/ 0 0 0
Condition0%0/3
not defined $text or $text =~ /[^A-Za-z0-9_-]/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $text or $text =~ /[^A-Za-z0-9_-]/
not defined $text $text =~ /[^A-Za-z0-9_-]/
Truth table0%0/3
not(A) or B
A= not defined $textB= $text =~ /[^A-Za-z0-9_-]/
ABresult
1X1
011
000
585 0 my $b64 = $text;
586 0 $b64 =~ tr/-_/+\//;
587 0 $b64 .= '=' x ( ( 4 - length($b64) % 4 ) % 4 );
588  
589 0 my $bytes = eval { decode_base64($b64) };
590 0 ▶ return $@ ? undef : $bytes;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
591 }
592  
593 0 ▶sub _base64_nopad {
Subroutine _base64_nopad: not called CC=1 SCAR=6.9
594 0 my ( $bytes ) = @_;
595  
596 0 my $out = encode_base64( $bytes, '' );
597 0 $out =~ s/=+\z//;
598 0 return $out;
599 }
600  
601 0 ▶sub _base64_nopad_decode {
Subroutine _base64_nopad_decode: not called CC=4 SCAR=30.0
602 0 my ( $text ) = @_;
603  
604 0 ▶ return undef if not defined $text or $text =~ /[^A-Za-z0-9+\/]/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $text or $text =~ m[[^A-Za-z0-9+/]] 0 0 0
Condition0%0/3
not defined $text or $text =~ m[[^A-Za-z0-9+/]]
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $text or $text =~ m[[^A-Za-z0-9+/]]
not defined $text $text =~ m[[^A-Za-z0-9+/]]
Truth table0%0/3
not(A) or B
A= not defined $textB= $text =~ m[[^A-Za-z0-9+/]]
ABresult
1X1
011
000
605 0 my $b64 = $text . ( '=' x ( ( 4 - length($text) % 4 ) % 4 ) );
606 0 my $bytes = eval { decode_base64($b64) };
607 0 ▶ return $@ ? undef : $bytes;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
608 }
609  
610 0 ▶sub _constant_time_eq {
Subroutine _constant_time_eq: not called CC=5 SCAR=34.0
611 0 my ( $left, $right ) = @_;
612  
613 0 ▶ return 0 if not defined $left or not defined $right;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left and defined $right 0 0 0
Condition0%0/3
defined $left and defined $right
!ll&&!rl&&r
000
MC/DC0%0/2
defined $left and defined $right
defined $left defined $right
Truth table0%0/3
A and B
A= defined $leftB= defined $right
ABresult
0X0
100
111
614 0 ▶ return 0 if length($left) != length($right);
Branch: 1 branch
BranchTrueFalseTotal
if length $left != length $right 0 0 0
615 0 my $diff = 0;
616 0 for my $i ( 0 .. length($left) - 1 ) {
617 0 $diff |= ord( substr( $left, $i, 1 ) )
618 ^ ord( substr( $right, $i, 1 ) );
619 }
620 0 return $diff == 0;
621 }
622  
623 0 ▶sub _pbkdf2_options {
Subroutine _pbkdf2_options: not called CC=1 SCAR=6.9
624 0 my ( $options, $label ) = @_;
625  
626 return (
627 0 _option_positive_integer(
628 $options,
629 'iterations',
630 $PBKDF2_SHA256_ITERATIONS,
631 $label,
632 ),
633 _option_positive_integer(
634 $options,
635 'length',
636 $PASSWORD_HASH_LENGTH,
637 $label,
638 ),
639 );
640 }
641  
642 0 ▶sub _argon2id_options {
Subroutine _argon2id_options: not called CC=1 SCAR=6.9
643 0 my ( $options, $label ) = @_;
644  
645 return (
646 0 _option_positive_integer(
647 $options,
648 'memory',
649 $ARGON2ID_MEMORY,
650 $label,
651 ),
652 _option_positive_integer(
653 $options,
654 'iterations',
655 $ARGON2ID_ITERATIONS,
656 $label,
657 ),
658 _option_positive_integer(
659 $options,
660 'parallelism',
661 $ARGON2ID_PARALLELISM,
662 $label,
663 ),
664 _option_positive_integer(
665 $options,
666 'length',
667 $PASSWORD_HASH_LENGTH,
668 $label,
669 ),
670 );
671 }
672  
673 0 ▶sub _scrypt_options {
Subroutine _scrypt_options: not called CC=4 SCAR=30.0
674 0 my ( $options, $label ) = @_;
675  
676 0 my $log_n = _option_positive_integer(
677 $options,
678 'log_n',
679 $SCRYPT_LOG_N,
680 $label,
681 );
682 0 my $n = _option_positive_integer(
683 $options,
684 'cost',
685 1 << $log_n,
686 $label,
687 );
688 0 ▶ _error( "$label option 'cost' must be a power of two" )
Branch: 1 branch
BranchTrueFalseTotal
if $n < 2 or ($n & $n - 1) != 0 0 0 0
Condition0%0/3
$n < 2 or ($n & $n - 1) != 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$n < 2 or ($n & $n - 1) != 0
$n < 2 ($n & $n - 1) != 0
Truth table0%0/3
A or B
A= $n < 2B= ($n & $n - 1) != 0
ABresult
1X1
011
000
689 if $n < 2 or ( $n & ( $n - 1 ) ) != 0;
690 0 $log_n = 0;
691 0 my $tmp = $n;
692 0 ▶ while ( $tmp > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp > 1) 0 0 0
693 0 $tmp >>= 1;
694 0 $log_n++;
695 }
696  
697 return (
698 0 $log_n,
699 $n,
700 _option_positive_integer( $options, 'r', $SCRYPT_R, $label ),
701 _option_positive_integer( $options, 'p', $SCRYPT_P, $label ),
702 _option_positive_integer(
703 $options,
704 'length',
705 $PASSWORD_HASH_LENGTH,
706 $label,
707 ),
708 );
709 }
710  
711 0 ▶sub _parse_pdkv {
Subroutine _parse_pdkv: not called CC=4 SCAR=30.0
712 0 my ( $text ) = @_;
713  
714 0 my %out;
715 0 for my $part ( split /,/, $text ) {
716 0 my ( $key, $value ) = split /=/, $part, 2;
717 0 ▶ return undef if not defined $key or not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and defined $value 0 0 0
Condition0%0/3
defined $key and defined $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key and defined $value
defined $key defined $value
Truth table0%0/3
A and B
A= defined $keyB= defined $value
ABresult
0X0
100
111
718 0 $out{$key} = $value;
719 }
720 0 return \%out;
721 }
722  
723 0 ▶sub _parse_password_hash {
Subroutine _parse_password_hash: not called CC=37 SCAR=72.5
724 0 my ( $encoded ) = @_;
725  
726 0 ▶ return { algorithm => 'crypt', encoded => $encoded }
Branch: 1 branch
BranchTrueFalseTotal
if defined $encoded and $encoded =~ /^\$[156]\$/ || $encoded =~ /^\$2[aby]\$/ 0 0 0
Condition0%0/6
defined $encoded and $encoded =~ /^\$[156]\$/ || $encoded =~ /^\$2[aby]\$/
!ll&&!rl&&r
000
$encoded =~ /^\$[156]\$/ or $encoded =~ /^\$2[aby]\$/
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $encoded and $encoded =~ /^\$[156]\$/ || $encoded =~ /^\$2[aby]\$/
defined $encoded $encoded =~ /^\$[156]\$/ $encoded =~ /^\$2[aby]\$/
Truth table0%0/4
A and B or C
A= defined $encodedB= $encoded =~ /^\$[156]\$/C= $encoded =~ /^\$2[aby]\$/
ABCresult
0XX0
1000
11X1
1011
727 if defined $encoded
728 and (
729 $encoded =~ /^\$[156]\$/
730 or $encoded =~ /^\$2[aby]\$/
731 );
732  
733 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoded and $encoded =~ / \A \$zuzu-pbkdf2-sha256 \$v=1 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x) 0 0 0
Condition0%0/3
defined $encoded and $encoded =~ / \A \$zuzu-pbkdf2-sha256 \$v=1 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
!ll&&!rl&&r
000
MC/DC0%0/2
defined $encoded and $encoded =~ / \A \$zuzu-pbkdf2-sha256 \$v=1 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
defined $encoded $encoded =~ / \A \$zuzu-pbkdf2-sha256 \$v=1 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
Truth table0%0/3
A and B
A= defined $encodedB= $encoded =~ / \A \$zuzu-pbkdf2-sha256 \$v=1 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
ABresult
0X0
100
111
734 defined $encoded
735 and $encoded =~ m{
736 \A
737 \$zuzu-pbkdf2-sha256
738 \$v=1
739 \$([^\$]+)
740 \$([^\$]+)
741 \$([^\$]+)
742 \z
743 }x
744 ) {
745 0 my ( $param_text, $salt_text, $hash_text ) = ( $1, $2, $3 );
746 0 ▶ my $params = _parse_pdkv($param_text) // return undef;
Condition0%0/2
_parse_pdkv($param_text) // (return undef)
l!l
00
MC/DC0%0/1
_parse_pdkv($param_text) // (return undef)
_parse_pdkv($param_text)
Truth table0%0/2
A
A= _parse_pdkv($param_text)
Aresult
11
00
747 return undef
748 if not defined $params->{i}
749 or not defined $params->{l}
750 or $params->{i} !~ /^\d+\z/
751 0 ▶ or $params->{l} !~ /^\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"i"} and defined $params->{"l"} and $params->{"i"} =~ /^\d+\z/ and $params->{"l"} =~ /^\d+\z/ 0 0 0
Condition0%0/9
defined $params->{"i"} and defined $params->{"l"} and $params->{"i"} =~ /^\d+\z/ and $params->{"l"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"i"} and defined $params->{"l"} and $params->{"i"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"i"} and defined $params->{"l"}
!ll&&!rl&&r
000
MC/DC0%0/4
defined $params->{"i"} and defined $params->{"l"} and $params->{"i"} =~ /^\d+\z/ and $params->{"l"} =~ /^\d+\z/
defined $params->{"i"} defined $params->{"l"} $params->{"i"} =~ /^\d+\z/ $params->{"l"} =~ /^\d+\z/
Truth table0%0/5
A and B and C and D
A= defined $params->{"i"}B= defined $params->{"l"}C= $params->{"i"} =~ /^\d+\z/D= $params->{"l"} =~ /^\d+\z/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
752 0 my $salt = _base64url_decode($salt_text);
753 0 my $hash = _base64url_decode($hash_text);
754 0 ▶ return undef if not defined $salt or not defined $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $salt and defined $hash 0 0 0
Condition0%0/3
defined $salt and defined $hash
!ll&&!rl&&r
000
MC/DC0%0/2
defined $salt and defined $hash
defined $salt defined $hash
Truth table0%0/3
A and B
A= defined $saltB= defined $hash
ABresult
0X0
100
111
755 return {
756 algorithm => 'pbkdf2-sha256',
757 iterations => int( $params->{i} ),
758 0 length => int( $params->{l} ),
759 salt => $salt,
760 hash => $hash,
761 };
762 }
763  
764 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoded and $encoded =~ / \A \$argon2id \$v=19 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x) 0 0 0
Condition0%0/3
defined $encoded and $encoded =~ / \A \$argon2id \$v=19 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
!ll&&!rl&&r
000
MC/DC0%0/2
defined $encoded and $encoded =~ / \A \$argon2id \$v=19 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
defined $encoded $encoded =~ / \A \$argon2id \$v=19 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
Truth table0%0/3
A and B
A= defined $encodedB= $encoded =~ / \A \$argon2id \$v=19 \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
ABresult
0X0
100
111
765 defined $encoded
766 and $encoded =~ m{
767 \A
768 \$argon2id
769 \$v=19
770 \$([^\$]+)
771 \$([^\$]+)
772 \$([^\$]+)
773 \z
774 }x
775 ) {
776 0 my ( $param_text, $salt_text, $hash_text ) = ( $1, $2, $3 );
777 0 ▶ my $params = _parse_pdkv($param_text) // return undef;
Condition0%0/2
_parse_pdkv($param_text) // (return undef)
l!l
00
MC/DC0%0/1
_parse_pdkv($param_text) // (return undef)
_parse_pdkv($param_text)
Truth table0%0/2
A
A= _parse_pdkv($param_text)
Aresult
11
00
778 return undef
779 if not defined $params->{m}
780 or not defined $params->{t}
781 or not defined $params->{p}
782 or $params->{m} !~ /^\d+\z/
783 or $params->{t} !~ /^\d+\z/
784 0 ▶ or $params->{p} !~ /^\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"m"} and defined $params->{"t"} and defined $params->{"p"} and $params->{"m"} =~ /^\d+\z/ and $params->{"t"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/ 0 0 0
Condition0%0/15
defined $params->{"m"} and defined $params->{"t"} and defined $params->{"p"} and $params->{"m"} =~ /^\d+\z/ and $params->{"t"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"m"} and defined $params->{"t"} and defined $params->{"p"} and $params->{"m"} =~ /^\d+\z/ and $params->{"t"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"m"} and defined $params->{"t"} and defined $params->{"p"} and $params->{"m"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"m"} and defined $params->{"t"} and defined $params->{"p"}
!ll&&!rl&&r
000
defined $params->{"m"} and defined $params->{"t"}
!ll&&!rl&&r
000
MC/DC0%0/6
defined $params->{"m"} and defined $params->{"t"} and defined $params->{"p"} and $params->{"m"} =~ /^\d+\z/ and $params->{"t"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/
defined $params->{"m"} defined $params->{"t"} defined $params->{"p"} $params->{"m"} =~ /^\d+\z/ $params->{"t"} =~ /^\d+\z/ $params->{"p"} =~ /^\d+\z/
Truth table0%0/7
A and B and C and D and E and F
A= defined $params->{"m"}B= defined $params->{"t"}C= defined $params->{"p"}D= $params->{"m"} =~ /^\d+\z/E= $params->{"t"} =~ /^\d+\z/F= $params->{"p"} =~ /^\d+\z/
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
785 0 my $salt = _base64_nopad_decode($salt_text);
786 0 my $hash = _base64_nopad_decode($hash_text);
787 0 ▶ return undef if not defined $salt or not defined $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $salt and defined $hash 0 0 0
Condition0%0/3
defined $salt and defined $hash
!ll&&!rl&&r
000
MC/DC0%0/2
defined $salt and defined $hash
defined $salt defined $hash
Truth table0%0/3
A and B
A= defined $saltB= defined $hash
ABresult
0X0
100
111
788 return {
789 algorithm => 'argon2id',
790 memory => int( $params->{m} ),
791 iterations => int( $params->{t} ),
792 0 parallelism => int( $params->{p} ),
793 length => length($hash),
794 salt => $salt,
795 hash => $hash,
796 };
797 }
798  
799 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $encoded and $encoded =~ / \A \$scrypt \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x) 0 0 0
Condition0%0/3
defined $encoded and $encoded =~ / \A \$scrypt \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
!ll&&!rl&&r
000
MC/DC0%0/2
defined $encoded and $encoded =~ / \A \$scrypt \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
defined $encoded $encoded =~ / \A \$scrypt \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
Truth table0%0/3
A and B
A= defined $encodedB= $encoded =~ / \A \$scrypt \$([^\$]+) \$([^\$]+) \$([^\$]+) \z /x
ABresult
0X0
100
111
800 defined $encoded
801 and $encoded =~ m{
802 \A
803 \$scrypt
804 \$([^\$]+)
805 \$([^\$]+)
806 \$([^\$]+)
807 \z
808 }x
809 ) {
810 0 my ( $param_text, $salt_text, $hash_text ) = ( $1, $2, $3 );
811 0 ▶ my $params = _parse_pdkv($param_text) // return undef;
Condition0%0/2
_parse_pdkv($param_text) // (return undef)
l!l
00
MC/DC0%0/1
_parse_pdkv($param_text) // (return undef)
_parse_pdkv($param_text)
Truth table0%0/2
A
A= _parse_pdkv($param_text)
Aresult
11
00
812 return undef
813 if not defined $params->{ln}
814 or not defined $params->{r}
815 or not defined $params->{p}
816 or not defined $params->{l}
817 or $params->{ln} !~ /^\d+\z/
818 or $params->{r} !~ /^\d+\z/
819 or $params->{p} !~ /^\d+\z/
820 0 ▶ or $params->{l} !~ /^\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"} and $params->{"ln"} =~ /^\d+\z/ and $params->{"r"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/ and $params->{"l"} =~ /^\d+\z/ 0 0 0
Condition0%0/21
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"} and $params->{"ln"} =~ /^\d+\z/ and $params->{"r"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/ and $params->{"l"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"} and $params->{"ln"} =~ /^\d+\z/ and $params->{"r"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"} and $params->{"ln"} =~ /^\d+\z/ and $params->{"r"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"} and $params->{"ln"} =~ /^\d+\z/
!ll&&!rl&&r
000
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"}
!ll&&!rl&&r
000
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"}
!ll&&!rl&&r
000
defined $params->{"ln"} and defined $params->{"r"}
!ll&&!rl&&r
000
MC/DC0%0/8
defined $params->{"ln"} and defined $params->{"r"} and defined $params->{"p"} and defined $params->{"l"} and $params->{"ln"} =~ /^\d+\z/ and $params->{"r"} =~ /^\d+\z/ and $params->{"p"} =~ /^\d+\z/ and $params->{"l"} =~ /^\d+\z/
defined $params->{"ln"} defined $params->{"r"} defined $params->{"p"} defined $params->{"l"} $params->{"ln"} =~ /^\d+\z/ $params->{"r"} =~ /^\d+\z/ $params->{"p"} =~ /^\d+\z/ $params->{"l"} =~ /^\d+\z/
Truth table0%0/9
A and B and C and D and E and F and G and H
A= defined $params->{"ln"}B= defined $params->{"r"}C= defined $params->{"p"}D= defined $params->{"l"}E= $params->{"ln"} =~ /^\d+\z/F= $params->{"r"} =~ /^\d+\z/G= $params->{"p"} =~ /^\d+\z/H= $params->{"l"} =~ /^\d+\z/
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
821 0 my $salt = _base64url_decode($salt_text);
822 0 my $hash = _base64url_decode($hash_text);
823 0 ▶ return undef if not defined $salt or not defined $hash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $salt and defined $hash 0 0 0
Condition0%0/3
defined $salt and defined $hash
!ll&&!rl&&r
000
MC/DC0%0/2
defined $salt and defined $hash
defined $salt defined $hash
Truth table0%0/3
A and B
A= defined $saltB= defined $hash
ABresult
0X0
100
111
824 return {
825 algorithm => 'scrypt',
826 log_n => int( $params->{ln} ),
827 r => int( $params->{r} ),
828 p => int( $params->{p} ),
829 0 length => int( $params->{l} ),
830 salt => $salt,
831 hash => $hash,
832 };
833 }
834  
835 0 return undef;
836 }
837  
838 0 ▶sub _password_hash_derive_bytes {
Subroutine _password_hash_derive_bytes: not called CC=4 SCAR=30.0
839 0 my ( $password, $algorithm, $salt, $options, $label ) = @_;
840  
841 0 ▶ if ( $algorithm eq 'pbkdf2-sha256' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "pbkdf2-sha256") 0 0 0
842 0 my ( $iterations, $length ) = _pbkdf2_options( $options, $label );
843 0 return pbkdf2( $password, $salt, $iterations, 'SHA256', $length );
844 }
845 0 ▶ if ( $algorithm eq 'argon2id' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "argon2id") 0 0 0
846 0 my ( $memory, $iterations, $parallelism, $length )
847 = _argon2id_options( $options, $label );
848 0 return argon2_pbkdf(
849 'argon2id',
850 $password,
851 $salt,
852 $iterations,
853 $memory,
854 $parallelism,
855 $length,
856 );
857 }
858 0 ▶ if ( $algorithm eq 'scrypt' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "scrypt") 0 0 0
859 0 my ( undef, $n, $r, $p, $length ) = _scrypt_options(
860 $options,
861 $label,
862 );
863 0 return scrypt_pbkdf( $password, $salt, $n, $r, $p, $length );
864 }
865  
866 0 _error( "$label does not support algorithm '$algorithm' for key derivation" );
867 }
868  
869 0 ▶sub _password_hash {
Subroutine _password_hash: not called CC=6 SCAR=37.4
870 0 my ( $password, $options_value ) = @_;
871  
872 0 my $label = 'PasswordHash.hash';
873 0 $password = _string_arg( $password, $label, 'String password' );
874 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
875 0 my $algorithm = _password_hash_algorithm( $options, $label );
876  
877 0 ▶ if ( $algorithm eq 'crypt' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "crypt") 0 0 0
878 0 my $salt = _base64_nopad( urandom(12) );
879 0 $salt =~ tr|+/|./|;
880 0 $salt = substr( $salt, 0, 16 );
881 0 return crypt( $password, "\$6\$rounds=5000\$$salt\$" );
882 }
883  
884 my $salt = exists $options->{salt}
885 0 ▶ ? _binary_bytes( $options->{salt}, $label, 'BinaryString salt' )
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{'salt'} ? : 0 0 0
886 : urandom($PASSWORD_HASH_SALT_LENGTH);
887 0 my $hash = _password_hash_derive_bytes(
888 $password,
889 $algorithm,
890 $salt,
891 $options,
892 $label,
893 );
894  
895 0 ▶ if ( $algorithm eq 'pbkdf2-sha256' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "pbkdf2-sha256") 0 0 0
896 0 my ( $iterations, $length ) = _pbkdf2_options( $options, $label );
897 0 return join '$',
898 '',
899 'zuzu-pbkdf2-sha256',
900 'v=1',
901 "i=$iterations,l=$length",
902 _base64url($salt),
903 _base64url($hash);
904 }
905 0 ▶ if ( $algorithm eq 'argon2id' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "argon2id") 0 0 0
906 0 my ( $memory, $iterations, $parallelism ) = _argon2id_options(
907 $options,
908 $label,
909 );
910 0 return join '$',
911 '',
912 'argon2id',
913 'v=19',
914 "m=$memory,t=$iterations,p=$parallelism",
915 _base64_nopad($salt),
916 _base64_nopad($hash);
917 }
918 0 ▶ if ( $algorithm eq 'scrypt' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq "scrypt") 0 0 0
919 0 my ( $log_n, undef, $r, $p, $length ) = _scrypt_options(
920 $options,
921 $label,
922 );
923 0 return join '$',
924 '',
925 'scrypt',
926 "ln=$log_n,r=$r,p=$p,l=$length",
927 _base64url($salt),
928 _base64url($hash);
929 }
930  
931 0 _error( "$label password hash algorithm '$algorithm' is not available" );
932 }
933  
934 0 ▶sub _password_hash_verify {
Subroutine _password_hash_verify: not called CC=8 SCAR=42.8
935 0 my ( $password, $encoded ) = @_;
936  
937 0 my $label = 'PasswordHash.verify';
938 0 $password = _string_arg( $password, $label, 'String password' );
939 0 $encoded = _string_arg( $encoded, $label, 'String encoded_hash' );
940 0 my $parsed = _parse_password_hash($encoded);
941 0 ▶ return _false() if not defined $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parsed 0 0 0
942 return _false()
943 0 ▶ if not $PASSWORD_HASH_CAPABILITIES{ $parsed->{algorithm} };
Branch: 1 branch
BranchTrueFalseTotal
unless $PASSWORD_HASH_CAPABILITIES{$parsed->{"algorithm"}} 0 0 0
944  
945 0 ▶ if ( $parsed->{algorithm} eq 'crypt' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed->{"algorithm"} eq "crypt") 0 0 0
946 0 my $candidate = crypt( $password, $encoded );
947 0 ▶ return defined $candidate && _constant_time_eq( $candidate, $encoded )
Branch: 1 branch
BranchTrueFalseTotal
defined $candidate && _constant_time_eq($candidate, $encoded) ? : 0 0 0
Condition0%0/3
defined $candidate and _constant_time_eq($candidate, $encoded)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $candidate and _constant_time_eq($candidate, $encoded)
defined $candidate _constant_time_eq($candidate, $encoded)
Truth table0%0/3
A and B
A= defined $candidateB= _constant_time_eq($candidate, $encoded)
ABresult
0X0
100
111
948 ? _true()
949 : _false();
950 }
951  
952 0 my %options = %{ $parsed };
953 0 my $hash = eval {
954 _password_hash_derive_bytes(
955 $password,
956 $parsed->{algorithm},
957 $parsed->{salt},
958 0 \%options,
959 $label,
960 );
961 };
962 0 ▶ return _false() if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
963 0 ▶ return _constant_time_eq( $hash, $parsed->{hash} ) ? _true() : _false();
Branch: 1 branch
BranchTrueFalseTotal
_constant_time_eq($hash, $parsed->{'hash'}) ? : 0 0 0
964 }
965  
966 0 ▶sub _password_hash_needs_rehash {
Subroutine _password_hash_needs_rehash: not called CC=17 SCAR=57.2
967 0 my ( $encoded, $options_value ) = @_;
968  
969 0 my $label = 'PasswordHash.needs_rehash';
970 0 $encoded = _string_arg( $encoded, $label, 'String encoded_hash' );
971 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
972 0 my $target = _password_hash_algorithm( $options, $label );
973 0 my $parsed = _parse_password_hash($encoded);
974 0 ▶ return _true() if not defined $parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parsed 0 0 0
975 0 ▶ return _true() if $parsed->{algorithm} ne $target;
Branch: 1 branch
BranchTrueFalseTotal
if $parsed->{"algorithm"} ne $target 0 0 0
976 0 ▶ return _true() if $parsed->{algorithm} eq 'crypt';
Branch: 1 branch
BranchTrueFalseTotal
if $parsed->{"algorithm"} eq "crypt" 0 0 0
977  
978 0 ▶ if ( $target eq 'pbkdf2-sha256' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "pbkdf2-sha256") 0 0 0
979 0 my ( $iterations, $length ) = _pbkdf2_options( $options, $label );
980 return $parsed->{iterations} >= $iterations
981 0 ▶ && $parsed->{length} == $length
Branch: 1 branch
BranchTrueFalseTotal
$parsed->{'iterations'} >= $iterations && $parsed->{'length'} == $length ? : 0 0 0
Condition0%0/3
$parsed->{"iterations"} >= $iterations and $parsed->{"length"} == $length
!ll&&!rl&&r
000
MC/DC0%0/2
$parsed->{"iterations"} >= $iterations and $parsed->{"length"} == $length
$parsed->{"iterations"} >= $iterations $parsed->{"length"} == $length
Truth table0%0/3
A and B
A= $parsed->{"iterations"} >= $iterationsB= $parsed->{"length"} == $length
ABresult
0X0
100
111
982 ? _false()
983 : _true();
984 }
985 0 ▶ if ( $target eq 'argon2id' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "argon2id") 0 0 0
986 0 my ( $memory, $iterations, $parallelism, $length )
987 = _argon2id_options( $options, $label );
988 return $parsed->{memory} >= $memory
989 && $parsed->{iterations} >= $iterations
990 && $parsed->{parallelism} == $parallelism
991 0 ▶ && $parsed->{length} == $length
Branch: 1 branch
BranchTrueFalseTotal
$parsed->{'memory'} >= $memory && $parsed->{'iterations'} >= $iterations && $parsed->{'parallelism'} == $parallelism && $parsed->{'length'} == $length ? : 0 0 0
Condition0%0/9
$parsed->{"memory"} >= $memory and $parsed->{"iterations"} >= $iterations and $parsed->{"parallelism"} == $parallelism and $parsed->{"length"} == $length
!ll&&!rl&&r
000
$parsed->{"memory"} >= $memory and $parsed->{"iterations"} >= $iterations and $parsed->{"parallelism"} == $parallelism
!ll&&!rl&&r
000
$parsed->{"memory"} >= $memory and $parsed->{"iterations"} >= $iterations
!ll&&!rl&&r
000
MC/DC0%0/4
$parsed->{"memory"} >= $memory and $parsed->{"iterations"} >= $iterations and $parsed->{"parallelism"} == $parallelism and $parsed->{"length"} == $length
$parsed->{"memory"} >= $memory $parsed->{"iterations"} >= $iterations $parsed->{"parallelism"} == $parallelism $parsed->{"length"} == $length
Truth table0%0/5
A and B and C and D
A= $parsed->{"memory"} >= $memoryB= $parsed->{"iterations"} >= $iterationsC= $parsed->{"parallelism"} == $parallelismD= $parsed->{"length"} == $length
ABCDresult
0XXX0
10XX0
110X0
11100
11111
992 ? _false()
993 : _true();
994 }
995 0 ▶ if ( $target eq 'scrypt' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq "scrypt") 0 0 0
996 0 my ( $log_n, undef, $r, $p, $length ) = _scrypt_options(
997 $options,
998 $label,
999 );
1000 return $parsed->{log_n} >= $log_n
1001 && $parsed->{r} == $r
1002 && $parsed->{p} == $p
1003 0 ▶ && $parsed->{length} == $length
Branch: 1 branch
BranchTrueFalseTotal
$parsed->{'log_n'} >= $log_n && $parsed->{'r'} == $r && $parsed->{'p'} == $p && $parsed->{'length'} == $length ? : 0 0 0
Condition0%0/9
$parsed->{"log_n"} >= $log_n and $parsed->{"r"} == $r and $parsed->{"p"} == $p and $parsed->{"length"} == $length
!ll&&!rl&&r
000
$parsed->{"log_n"} >= $log_n and $parsed->{"r"} == $r and $parsed->{"p"} == $p
!ll&&!rl&&r
000
$parsed->{"log_n"} >= $log_n and $parsed->{"r"} == $r
!ll&&!rl&&r
000
MC/DC0%0/4
$parsed->{"log_n"} >= $log_n and $parsed->{"r"} == $r and $parsed->{"p"} == $p and $parsed->{"length"} == $length
$parsed->{"log_n"} >= $log_n $parsed->{"r"} == $r $parsed->{"p"} == $p $parsed->{"length"} == $length
Truth table0%0/5
A and B and C and D
A= $parsed->{"log_n"} >= $log_nB= $parsed->{"r"} == $rC= $parsed->{"p"} == $pD= $parsed->{"length"} == $length
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1004 ? _false()
1005 : _true();
1006 }
1007  
1008 0 return _true();
1009 }
1010  
1011 0 ▶sub _password_hash_derive_key {
Subroutine _password_hash_derive_key: not called CC=3 SCAR=24.8
1012 0 my ( $password, $options_value ) = @_;
1013  
1014 0 my $label = 'PasswordHash.derive_key';
1015 0 $password = _string_arg( $password, $label, 'String password' );
1016 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
1017 0 my $algorithm = _password_hash_algorithm( $options, $label );
1018 0 ▶ _error( "$label does not support crypt" ) if $algorithm eq 'crypt';
Branch: 1 branch
BranchTrueFalseTotal
if $algorithm eq "crypt" 0 0 0
1019 _error( "$label expects BinaryString salt" )
1020 0 ▶ if not exists $options->{salt};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options->{"salt"} 0 0 0
1021 0 my $salt = _binary_bytes( $options->{salt}, $label, 'BinaryString salt' );
1022  
1023 0 return Zuzu::Value::BinaryString->new(
1024 bytes => _password_hash_derive_bytes(
1025 $password,
1026 $algorithm,
1027 $salt,
1028 $options,
1029 $label,
1030 ),
1031 );
1032 }
1033  
1034 0 ▶sub _signing_algorithm {
Subroutine _signing_algorithm: not called CC=3 SCAR=24.8
1035 0 my ( $value, $label ) = @_;
1036  
1037 0 ▶ $value = 'ed25519' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1038 _error( "$label signing algorithm '$value' is not available" )
1039 0 ▶ if not $SIGNING_ALGORITHMS{"$value"};
Branch: 1 branch
BranchTrueFalseTotal
unless $SIGNING_ALGORITHMS{"$value"} 0 0 0
1040  
1041 0 return "$value";
1042 }
1043  
1044 0 ▶sub _signing_options {
Subroutine _signing_options: not called CC=1 SCAR=6.9
1045 0 my ( $options_value, $label ) = @_;
1046  
1047 0 return _optional_dict_map( $options_value, $label, 'Dict options' );
1048 }
1049  
1050 0 ▶sub _signing_algorithm_option {
Subroutine _signing_algorithm_option: not called CC=2 SCAR=17.9
1051 0 my ( $options, $label ) = @_;
1052  
1053 0 ▶ return undef if not defined $options->{algorithm};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{"algorithm"} 0 0 0
1054 0 return _signing_algorithm( $options->{algorithm}, $label );
1055 }
1056  
1057 0 ▶sub _signing_meta {
Subroutine _signing_meta: not called CC=1 SCAR=6.9
1058 0 my ( $algorithm ) = @_;
1059  
1060 0 return $SIGNING_ALGORITHMS{$algorithm};
1061 }
1062  
1063 0 ▶sub _ecdsa_algorithm_for_public_length {
Subroutine _ecdsa_algorithm_for_public_length: not called CC=4 SCAR=30.0
1064 0 my ( $length, $label ) = @_;
1065  
1066 0 ▶ return 'ecdsa-p256-sha256' if $length == 65;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 65 0 0 0
1067 0 ▶ return 'ecdsa-p384-sha384' if $length == 97;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 97 0 0 0
1068 0 ▶ return 'ecdsa-p521-sha512' if $length == 133;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 133 0 0 0
1069 0 _error( "$label expects a 32-byte Ed25519 key, "
1070 . '65-byte P-256 public key, 97-byte P-384 public key, '
1071 . 'or 133-byte P-521 public key' );
1072 }
1073  
1074 0 ▶sub _ecdsa_algorithm_for_key {
Subroutine _ecdsa_algorithm_for_key: not called CC=5 SCAR=34.0
1075 0 my ( $pk, $label ) = @_;
1076  
1077 0 my $public = eval { $pk->export_key_raw('public') };
1078 0 ▶ _error( "$label expects an Ed25519, P-256, or P-384 key" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $public 0 0 0
1079 if not defined $public;
1080 0 ▶ return 'ecdsa-p256-sha256' if length($public) == 65;
Branch: 1 branch
BranchTrueFalseTotal
if length $public == 65 0 0 0
1081 0 ▶ return 'ecdsa-p384-sha384' if length($public) == 97;
Branch: 1 branch
BranchTrueFalseTotal
if length $public == 97 0 0 0
1082 0 ▶ return 'ecdsa-p521-sha512' if length($public) == 133;
Branch: 1 branch
BranchTrueFalseTotal
if length $public == 133 0 0 0
1083 0 _error( "$label expects a P-256, P-384, or P-521 key" );
1084 }
1085  
1086 0 ▶sub _new_key_for_algorithm {
Subroutine _new_key_for_algorithm: not called CC=3 SCAR=24.8
1087 0 my ( $algorithm ) = @_;
1088  
1089 0 my $meta = _signing_meta($algorithm);
1090 0 ▶ return Crypt::PK::Ed25519->new if $meta->{type} eq 'ed25519';
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"type"} eq "ed25519" 0 0 0
1091 0 ▶ return Crypt::PK::ECC->new if $meta->{type} eq 'ecdsa';
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"type"} eq "ecdsa" 0 0 0
1092 0 _error( "Unsupported signing algorithm '$algorithm'" );
1093 }
1094  
1095 0 ▶sub _key_format {
Subroutine _key_format: not called CC=4 SCAR=30.0
1096 0 my ( $options_value, $value, $label ) = @_;
1097  
1098 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
1099 0 ▶ return "$options->{format}" if defined $options->{format};
Branch: 1 branch
BranchTrueFalseTotal
if defined $options->{"format"} 0 0 0
1100 0 ▶ return blessed($value) && $value->isa( 'Zuzu::Value::BinaryString' )
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($value) && $value->isa('Zuzu::Value::BinaryString') ? : 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::BinaryString")
builtin::blessed($value) $value->isa("Zuzu::Value::BinaryString")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
1101 ? 'raw'
1102 : 'pem';
1103 }
1104  
1105 0 ▶sub _new_signing_key {
Subroutine _new_signing_key: not called CC=1 SCAR=6.9
1106 0 my ( $class, $algorithm, $pk ) = @_;
1107  
1108 0 return native_object(
1109 class => $class,
1110 slots => {
1111 _algorithm => $algorithm,
1112 _pk => $pk,
1113 },
1114 const => {
1115 _algorithm => 1,
1116 _pk => 1,
1117 },
1118 );
1119 }
1120  
1121 0 ▶sub _new_public_key {
Subroutine _new_public_key: not called CC=1 SCAR=6.9
1122 0 my ( $class, $algorithm, $pk ) = @_;
1123  
1124 0 return native_object(
1125 class => $class,
1126 slots => {
1127 _algorithm => $algorithm,
1128 _pk => $pk,
1129 },
1130 const => {
1131 _algorithm => 1,
1132 _pk => 1,
1133 },
1134 );
1135 }
1136  
1137 0 ▶sub _new_key_agreement {
Subroutine _new_key_agreement: not called CC=1 SCAR=6.9
1138 0 my ( $class, $algorithm, $pk ) = @_;
1139  
1140 0 return native_object(
1141 class => $class,
1142 slots => {
1143 _algorithm => $algorithm,
1144 _pk => $pk,
1145 },
1146 const => {
1147 _algorithm => 1,
1148 _pk => 1,
1149 },
1150 );
1151 }
1152  
1153 0 ▶sub _signing_private_state {
Subroutine _signing_private_state: not called CC=4 SCAR=30.0
1154 0 my ( $self, $label ) = @_;
1155  
1156 0 ▶ _error( "TypeException: $label expects SigningKey" )
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($self) && $self->can("class") or $self->class->name ne "SigningKey" 0 0 0
Condition0%0/6
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "SigningKey"
l!l&&r!l&&!r
000
builtin::blessed($self) && $self->can('class')
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "SigningKey"
builtin::blessed($self) $self->can('class') $self->class->name ne "SigningKey"
Truth table0%0/4
not(A && B) or C
A= builtin::blessed($self)B= $self->can('class')C= $self->class->name ne "SigningKey"
ABCresult
0XX1
10X1
1111
1100
1157 if not blessed($self)
1158 or not $self->can('class')
1159 or $self->class->name ne 'SigningKey';
1160 0 return ( $self->slots->{_algorithm}, $self->slots->{_pk} );
1161 }
1162  
1163 0 ▶sub _public_key_state {
Subroutine _public_key_state: not called CC=4 SCAR=30.0
1164 0 my ( $self, $label ) = @_;
1165  
1166 0 ▶ _error( "TypeException: $label expects PublicKey" )
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($self) && $self->can("class") or $self->class->name ne "PublicKey" 0 0 0
Condition0%0/6
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "PublicKey"
l!l&&r!l&&!r
000
builtin::blessed($self) && $self->can('class')
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "PublicKey"
builtin::blessed($self) $self->can('class') $self->class->name ne "PublicKey"
Truth table0%0/4
not(A && B) or C
A= builtin::blessed($self)B= $self->can('class')C= $self->class->name ne "PublicKey"
ABCresult
0XX1
10X1
1111
1100
1167 if not blessed($self)
1168 or not $self->can('class')
1169 or $self->class->name ne 'PublicKey';
1170 0 return ( $self->slots->{_algorithm}, $self->slots->{_pk} );
1171 }
1172  
1173 0 ▶sub _signing_public_state {
Subroutine _signing_public_state: not called CC=2 SCAR=17.9
1174 0 my ( $self, $label ) = @_;
1175  
1176 0 my ( $algorithm, $pk ) = _public_key_state( $self, $label );
1177 _error( "$label expects a signing public key" )
1178 0 ▶ if not $SIGNING_ALGORITHMS{$algorithm};
Branch: 1 branch
BranchTrueFalseTotal
unless $SIGNING_ALGORITHMS{$algorithm} 0 0 0
1179 0 return ( $algorithm, $pk );
1180 }
1181  
1182 0 ▶sub _key_agreement_state {
Subroutine _key_agreement_state: not called CC=4 SCAR=30.0
1183 0 my ( $self, $label ) = @_;
1184  
1185 0 ▶ _error( "TypeException: $label expects KeyAgreement" )
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($self) && $self->can("class") or $self->class->name ne "KeyAgreement" 0 0 0
Condition0%0/6
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "KeyAgreement"
l!l&&r!l&&!r
000
builtin::blessed($self) && $self->can('class')
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "KeyAgreement"
builtin::blessed($self) $self->can('class') $self->class->name ne "KeyAgreement"
Truth table0%0/4
not(A && B) or C
A= builtin::blessed($self)B= $self->can('class')C= $self->class->name ne "KeyAgreement"
ABCresult
0XX1
10X1
1111
1100
1186 if not blessed($self)
1187 or not $self->can('class')
1188 or $self->class->name ne 'KeyAgreement';
1189 0 return ( $self->slots->{_algorithm}, $self->slots->{_pk} );
1190 }
1191  
1192 0 ▶sub _key_agreement_algorithm {
Subroutine _key_agreement_algorithm: not called CC=3 SCAR=24.8
1193 0 my ( $value, $label ) = @_;
1194  
1195 0 ▶ $value = 'x25519' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1196 0 ▶ _error( "$label only supports x25519" )
Branch: 1 branch
BranchTrueFalseTotal
if "$value" ne "x25519" 0 0 0
1197 if "$value" ne 'x25519';
1198  
1199 0 return 'x25519';
1200 }
1201  
1202 0 ▶sub _key_agreement_algorithm_option {
Subroutine _key_agreement_algorithm_option: not called CC=2 SCAR=17.9
1203 0 my ( $options, $label ) = @_;
1204  
1205 0 ▶ return undef if not defined $options->{algorithm};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options->{"algorithm"} 0 0 0
1206 0 return _key_agreement_algorithm( $options->{algorithm}, $label );
1207 }
1208  
1209 0 ▶sub _x25519_private {
Subroutine _x25519_private: not called CC=3 SCAR=24.8
1210 0 my ( $bytes, $label ) = @_;
1211  
1212 0 ▶ _error( "$label expects a 32-byte raw private key" )
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes != 32 0 0 0
1213 if length($bytes) != 32;
1214 0 my $pk = Crypt::PK::X25519->new;
1215 _error( "$label expects a valid X25519 private key" )
1216 0 ▶ if not eval { $pk->import_key_raw( $bytes, 'private' ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pk->import_key_raw($bytes, "private"); 1 } } 0 0 0
1217 0 return $pk;
1218 }
1219  
1220 0 ▶sub _x25519_public {
Subroutine _x25519_public: not called CC=3 SCAR=24.8
1221 0 my ( $bytes, $label ) = @_;
1222  
1223 0 ▶ _error( "$label expects a 32-byte raw public key" )
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes != 32 0 0 0
1224 if length($bytes) != 32;
1225 0 my $pk = Crypt::PK::X25519->new;
1226 _error( "$label expects a valid X25519 public key" )
1227 0 ▶ if not eval { $pk->import_key_raw( $bytes, 'public' ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pk->import_key_raw($bytes, "public"); 1 } } 0 0 0
1228 0 return $pk;
1229 }
1230  
1231 0 ▶sub _key_agreement_generate {
Subroutine _key_agreement_generate: not called CC=1 SCAR=6.9
1232 0 my ( $key_agreement_class, $algorithm ) = @_;
1233  
1234 0 my $label = 'KeyAgreement.generate';
1235 0 $algorithm = _key_agreement_algorithm( $algorithm, $label );
1236 0 my $pk = Crypt::PK::X25519->new;
1237 0 $pk->generate_key;
1238 0 return _new_key_agreement( $key_agreement_class, $algorithm, $pk );
1239 }
1240  
1241 0 ▶sub _key_agreement_import_private {
Subroutine _key_agreement_import_private: not called CC=2 SCAR=17.9
1242 0 my ( $key_agreement_class, $key, $options ) = @_;
1243  
1244 0 my $label = 'KeyAgreement.import_private';
1245 0 my $opts = _optional_dict_map( $options, $label, 'Dict options' );
1246 0 my $format = _key_format( $options, $key, $label );
1247 0 _key_agreement_algorithm_option( $opts, $label );
1248 0 ▶ _error( "$label only supports raw format" )
Branch: 1 branch
BranchTrueFalseTotal
if $format ne "raw" 0 0 0
1249 if $format ne 'raw';
1250 0 my $bytes = _binary_bytes( $key, $label, 'BinaryString key' );
1251 0 my $pk = _x25519_private( $bytes, $label );
1252 0 return _new_key_agreement( $key_agreement_class, 'x25519', $pk );
1253 }
1254  
1255 0 ▶sub _key_agreement_import_public {
Subroutine _key_agreement_import_public: not called CC=2 SCAR=17.9
1256 0 my ( $public_key_class, $key, $options ) = @_;
1257  
1258 0 my $label = 'KeyAgreement.import_public';
1259 0 my $opts = _optional_dict_map( $options, $label, 'Dict options' );
1260 0 my $format = _key_format( $options, $key, $label );
1261 0 _key_agreement_algorithm_option( $opts, $label );
1262 0 ▶ _error( "$label only supports raw format" )
Branch: 1 branch
BranchTrueFalseTotal
if $format ne "raw" 0 0 0
1263 if $format ne 'raw';
1264 0 my $bytes = _binary_bytes( $key, $label, 'BinaryString key' );
1265 0 my $pk = _x25519_public( $bytes, $label );
1266 0 return _new_public_key( $public_key_class, 'x25519', $pk );
1267 }
1268  
1269 0 ▶sub _key_agreement_public_key {
Subroutine _key_agreement_public_key: not called CC=1 SCAR=6.9
1270 0 my ( $public_key_class, $self ) = @_;
1271  
1272 0 my ( $algorithm, $pk ) = _key_agreement_state(
1273 $self,
1274 'KeyAgreement.public_key',
1275 );
1276 0 my $public = _x25519_public(
1277 $pk->export_key_raw('public'),
1278 'KeyAgreement.public_key',
1279 );
1280 0 return _new_public_key( $public_key_class, $algorithm, $public );
1281 }
1282  
1283 0 ▶sub _key_agreement_export_private {
Subroutine _key_agreement_export_private: not called CC=3 SCAR=24.8
1284 0 my ( $self, $options_value ) = @_;
1285  
1286 0 my $label = 'KeyAgreement.export_private';
1287 0 my ( undef, $pk ) = _key_agreement_state( $self, $label );
1288 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
1289 0 ▶ my $format = defined $options->{format} ? "$options->{format}" : 'raw';
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'format'} ? : 0 0 0
1290 0 ▶ _error( "$label only supports raw format" )
Branch: 1 branch
BranchTrueFalseTotal
if $format ne "raw" 0 0 0
1291 if $format ne 'raw';
1292 0 return Zuzu::Value::BinaryString->new(
1293 bytes => $pk->export_key_raw('private'),
1294 );
1295 }
1296  
1297 0 ▶sub _key_agreement_derive {
Subroutine _key_agreement_derive: not called CC=4 SCAR=30.0
1298 0 my ( $self, $peer ) = @_;
1299  
1300 0 my $label = 'KeyAgreement.derive';
1301 0 my ( $algorithm, $pk ) = _key_agreement_state( $self, $label );
1302 0 my ( $peer_algorithm, $peer_pk ) = _public_key_state( $peer, $label );
1303 0 ▶ _error( "$label expects an x25519 public key" )
Branch: 1 branch
BranchTrueFalseTotal
if $algorithm ne "x25519" or $peer_algorithm ne "x25519" 0 0 0
Condition0%0/3
$algorithm ne "x25519" or $peer_algorithm ne "x25519"
l!l&&r!l&&!r
000
MC/DC0%0/2
$algorithm ne "x25519" or $peer_algorithm ne "x25519"
$algorithm ne "x25519" $peer_algorithm ne "x25519"
Truth table0%0/3
A or B
A= $algorithm ne "x25519"B= $peer_algorithm ne "x25519"
ABresult
1X1
011
000
1304 if $algorithm ne 'x25519' or $peer_algorithm ne 'x25519';
1305 0 my $secret = eval { $pk->shared_secret($peer_pk) };
1306 0 ▶ _error( "$label failed" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $secret 0 0 0
1307 if not defined $secret;
1308 0 return Zuzu::Value::BinaryString->new( bytes => $secret );
1309 }
1310  
1311 2 ▶sub _pem_blocks {
Subroutine _pem_blocks: called CC=5 SCAR=16.5
1312 2 my ( $pem, $label ) = @_;
1313  
1314 2 my @blocks;
1315 2 ▶ while (
Branch: 1 branch
BranchTrueFalseTotal
if ($pem =~ / -----BEGIN\ CERTIFICATE----- (.*?) -----END\ CERTIFICATE----- /gsx) 2 2 4
1316 $pem =~ m{
1317 -----BEGIN\ CERTIFICATE-----
1318 (.*?)
1319 -----END\ CERTIFICATE-----
1320 }xsg
1321 ) {
1322 2 my $body = $1;
1323 2 $body =~ s/\s+//g;
1324 2 my $der = eval { decode_base64($body) };
1325 2 ▶ _error( "$label expects PEM certificate text" )
Branch: 1 branch
BranchTrueFalseTotal
if not defined $der or length $der == 0 0 2 2
Condition33%1/3
not defined $der or length $der == 0
l!l&&r!l&&!r
002
MC/DC0%0/2
not defined $der or length $der == 0
not defined $der length $der == 0
Truth table33%1/3
not(A) or B
A= not defined $derB= length $der == 0
ABresult
1X1
011
000
1326 if not defined $der or length($der) == 0;
1327 2 push @blocks, $der;
1328 }
1329 2 ▶ _error( "$label expects PEM certificate text" ) if not @blocks;
Branch: 1 branch
BranchTrueFalseTotal
unless @blocks 0 2 2
1330 2 return @blocks;
1331 }
1332  
1333 2 ▶sub _der_to_pem_certificate {
Subroutine _der_to_pem_certificate: called CC=1 SCAR=0.0
1334 2 my ( $der ) = @_;
1335  
1336 2 my $encoded = encode_base64( $der, '' );
1337 2 $encoded =~ s/(.{1,64})/$1\n/g;
1338 2 return "-----BEGIN CERTIFICATE-----\n"
1339 . $encoded
1340 . "-----END CERTIFICATE-----\n";
1341 }
1342  
1343 2 ▶sub _parse_x509_der {
Subroutine _parse_x509_der: called CC=2 SCAR=7.0
1344 2 my ( $certificate_class, $der, $label ) = @_;
1345  
1346 2 my $x509 = eval {
1347 2 Crypt::OpenSSL::X509->new_from_string(
1348 $der,
1349 Crypt::OpenSSL::X509::FORMAT_ASN1(),
1350 );
1351 };
1352 2 ▶ _error( "$label expects DER X.509 certificate data" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x509 0 2 2
1353 if not defined $x509;
1354  
1355 2 return native_object(
1356 class => $certificate_class,
1357 slots => {
1358 _der => $der,
1359 _x509 => $x509,
1360 },
1361 const => {
1362 _der => 1,
1363 _x509 => 1,
1364 },
1365 );
1366 }
1367  
1368 1 ▶sub _certificate_parse {
Subroutine _certificate_parse: called CC=3 SCAR=12.0
1369 1 my ( $certificate_class, $input ) = @_;
1370  
1371 1 my $label = 'Certificate.parse';
1372 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($input) and $input->isa("Zuzu::Value::BinaryString")) 0 1 1
Condition33%1/3
builtin::blessed($input) and $input->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
100
MC/DC0%0/2
builtin::blessed($input) and $input->isa("Zuzu::Value::BinaryString")
builtin::blessed($input) $input->isa("Zuzu::Value::BinaryString")
Truth table33%1/3
A and B
A= builtin::blessed($input)B= $input->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
1373 blessed($input)
1374 and $input->isa( 'Zuzu::Value::BinaryString' )
1375 ) {
1376 0 return _parse_x509_der( $certificate_class, $input->bytes, $label );
1377 }
1378 1 my $pem = _string_arg( $input, $label, 'String pem' );
1379 1 my ( $der ) = _pem_blocks( $pem, $label );
1380 1 return _parse_x509_der( $certificate_class, $der, $label );
1381 }
1382  
1383 0 ▶sub _certificate_parse_chain {
Subroutine _certificate_parse_chain: not called CC=3 SCAR=24.8
1384 0 my ( $certificate_class, $input ) = @_;
1385  
1386 0 my $label = 'Certificate.parse_chain';
1387 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($input) and $input->isa("Zuzu::Value::BinaryString")) 0 0 0
Condition0%0/3
builtin::blessed($input) and $input->isa("Zuzu::Value::BinaryString")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($input) and $input->isa("Zuzu::Value::BinaryString")
builtin::blessed($input) $input->isa("Zuzu::Value::BinaryString")
Truth table0%0/3
A and B
A= builtin::blessed($input)B= $input->isa("Zuzu::Value::BinaryString")
ABresult
0X0
100
111
1388 blessed($input)
1389 and $input->isa( 'Zuzu::Value::BinaryString' )
1390 ) {
1391 0 return _array(
1392 _parse_x509_der( $certificate_class, $input->bytes, $label ),
1393 );
1394 }
1395 0 my $pem = _string_arg( $input, $label, 'String pem' );
1396 return _array(
1397 map {
1398 0 _parse_x509_der( $certificate_class, $_, $label );
1399 } _pem_blocks( $pem, $label )
1400 );
1401 }
1402  
1403 0 ▶sub _certificate_state {
Subroutine _certificate_state: not called CC=4 SCAR=30.0
1404 0 my ( $self, $label ) = @_;
1405  
1406 0 ▶ _error( "TypeException: $label expects Certificate" )
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($self) && $self->can("class") or $self->class->name ne "Certificate" 0 0 0
Condition0%0/6
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "Certificate"
l!l&&r!l&&!r
000
builtin::blessed($self) && $self->can('class')
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "Certificate"
builtin::blessed($self) $self->can('class') $self->class->name ne "Certificate"
Truth table0%0/4
not(A && B) or C
A= builtin::blessed($self)B= $self->can('class')C= $self->class->name ne "Certificate"
ABCresult
0XX1
10X1
1111
1100
1407 if not blessed($self)
1408 or not $self->can('class')
1409 or $self->class->name ne 'Certificate';
1410 0 return ( $self->slots->{_der}, $self->slots->{_x509} );
1411 }
1412  
1413 0 ▶sub _certificate_net_x509 {
Subroutine _certificate_net_x509: not called CC=3 SCAR=24.8
1414 0 my ( $der, $label ) = @_;
1415  
1416 0 my $bio = Net::SSLeay::BIO_new( Net::SSLeay::BIO_s_mem() );
1417 0 ▶ _error( "$label failed to initialize certificate parser" )
Branch: 1 branch
BranchTrueFalseTotal
unless $bio 0 0 0
1418 if not $bio;
1419 0 Net::SSLeay::BIO_write( $bio, $der );
1420 0 my $x509 = Net::SSLeay::d2i_X509_bio($bio);
1421 0 Net::SSLeay::BIO_free($bio);
1422 0 ▶ _error( "$label expects DER X.509 certificate data" )
Branch: 1 branch
BranchTrueFalseTotal
unless $x509 0 0 0
1423 if not $x509;
1424 0 return $x509;
1425 }
1426  
1427 0 ▶sub _certificate_array_arg {
Subroutine _certificate_array_arg: not called CC=5 SCAR=34.0
1428 0 my ( $value, $label ) = @_;
1429  
1430 0 ▶ _error( "TypeException: $label expects Array chain, got "
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($value) and $value->isa("Zuzu::Value::Array") 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
builtin::blessed($value) $value->isa("Zuzu::Value::Array")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Array")
ABresult
0X0
100
111
1431 . _type_name($value) )
1432 if not blessed($value)
1433 or not $value->isa( 'Zuzu::Value::Array' );
1434 0 my @items = $value->resolved_items;
1435 0 ▶ _error( "$label expects a non-empty certificate chain" )
Branch: 1 branch
BranchTrueFalseTotal
unless @items 0 0 0
1436 if not @items;
1437 0 for my $item ( @items ) {
1438 0 _certificate_state( $item, $label );
1439 }
1440 0 return @items;
1441 }
1442  
1443 0 ▶sub _certificate_root_ders {
Subroutine _certificate_root_ders: not called CC=8 SCAR=42.8
1444 0 my ( $value, $label ) = @_;
1445  
1446 0 ▶ return () if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1447 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value) and $value->can("class") and $value->class->name eq "Certificate") 0 0 0
Condition0%0/6
builtin::blessed($value) and $value->can("class") and $value->class->name eq "Certificate"
!ll&&!rl&&r
000
builtin::blessed($value) and $value->can("class")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($value) and $value->can("class") and $value->class->name eq "Certificate"
builtin::blessed($value) $value->can("class") $value->class->name eq "Certificate"
Truth table0%0/4
A and B and C
A= builtin::blessed($value)B= $value->can("class")C= $value->class->name eq "Certificate"
ABCresult
0XX0
10X0
1100
1111
1448 blessed($value)
1449 and $value->can('class')
1450 and $value->class->name eq 'Certificate'
1451 ) {
1452 0 my ( $der ) = _certificate_state( $value, $label );
1453 0 return ($der);
1454 }
1455 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value) and $value->isa("Zuzu::Value::Array")) 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Array")
builtin::blessed($value) $value->isa("Zuzu::Value::Array")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Array")
ABresult
0X0
100
111
1456 blessed($value)
1457 and $value->isa( 'Zuzu::Value::Array' )
1458 ) {
1459 return map {
1460 0 _certificate_root_ders( $_, $label );
1461 } $value->resolved_items;
1462 }
1463 0 ▶ if ( not blessed($value) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($value)) 0 0 0
1464 0 return _pem_blocks( "$value", $label );
1465 }
1466 0 _error( 'TypeException: '
1467 . "$label expects roots to be Certificate, String PEM, Array, "
1468 . 'or null' );
1469 }
1470  
1471 0 ▶sub _certificate_bool_option {
Subroutine _certificate_bool_option: not called CC=5 SCAR=34.0
1472 0 my ( $value, $label, $name, $default ) = @_;
1473  
1474 0 ▶ return $default if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1475 0 ▶ return $value->value ? 1 : 0
Branch: 2 branches
BranchTrueFalseTotal
if builtin::blessed($value) and $value->isa("Zuzu::Value::Boolean") 0 0 0
$value->value ? : 0 0 0
Condition0%0/3
builtin::blessed($value) and $value->isa("Zuzu::Value::Boolean")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($value) and $value->isa("Zuzu::Value::Boolean")
builtin::blessed($value) $value->isa("Zuzu::Value::Boolean")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Value::Boolean")
ABresult
0X0
100
111
1476 if blessed($value)
1477 and $value->isa( 'Zuzu::Value::Boolean' );
1478 0 _error( "TypeException: $label option '$name' expects Boolean" );
1479 }
1480  
1481 0 ▶sub _certificate_time_option {
Subroutine _certificate_time_option: not called CC=8 SCAR=42.8
1482 0 my ( $value, $label ) = @_;
1483  
1484 0 ▶ return time if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
1485 0 ▶ return int( 0 + $value )
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($value) and &looks_like_number($value) 0 0 0
Condition0%0/3
not builtin::blessed($value) and &looks_like_number($value)
!ll&&!rl&&r
000
MC/DC0%0/2
not builtin::blessed($value) and &looks_like_number($value)
not builtin::blessed($value) &looks_like_number($value)
Truth table0%0/3
not(A) and B
A= not builtin::blessed($value)B= &looks_like_number($value)
ABresult
0X0
100
111
1486 if not blessed($value) and looks_like_number($value);
1487 return int( 0 + $value->slots->{_epoch} )
1488 if blessed($value)
1489 and $value->can('class')
1490 and $value->class->name eq 'Time'
1491 0 ▶ and exists $value->slots->{_epoch};
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value) and $value->can("class") and $value->class->name eq "Time" and exists $value->slots->{"_epoch"} 0 0 0
Condition0%0/9
builtin::blessed($value) and $value->can("class") and $value->class->name eq "Time" and exists $value->slots->{"_epoch"}
!ll&&!rl&&r
000
builtin::blessed($value) and $value->can("class") and $value->class->name eq "Time"
!ll&&!rl&&r
000
builtin::blessed($value) and $value->can("class")
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::blessed($value) and $value->can("class") and $value->class->name eq "Time" and exists $value->slots->{"_epoch"}
builtin::blessed($value) $value->can("class") $value->class->name eq "Time" exists $value->slots->{"_epoch"}
Truth table0%0/5
A and B and C and D
A= builtin::blessed($value)B= $value->can("class")C= $value->class->name eq "Time"D= exists $value->slots->{"_epoch"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1492 0 _error(
1493 "TypeException: $label option 'time' expects Time, Number, or null",
1494 );
1495 }
1496  
1497 0 ▶sub _certificate_verify_reason {
Subroutine _certificate_verify_reason: not called CC=11 SCAR=48.8
1498 0 my ( $error ) = @_;
1499  
1500 0 ▶ $error = lc( $error // '' );
Condition0%0/2
$error // ""
l!l
00
MC/DC0%0/1
$error // ""
$error
Truth table0%0/2
A
A= $error
Aresult
11
00
1501 0 ▶ return 'ok' if $error eq '' or $error eq 'ok';
Branch: 1 branch
BranchTrueFalseTotal
if $error eq "" or $error eq "ok" 0 0 0
Condition0%0/3
$error eq "" or $error eq "ok"
l!l&&r!l&&!r
000
MC/DC0%0/2
$error eq "" or $error eq "ok"
$error eq "" $error eq "ok"
Truth table0%0/3
A or B
A= $error eq ""B= $error eq "ok"
ABresult
1X1
011
000
1502 0 ▶ return 'hostname-mismatch' if $error =~ /hostname/;
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /hostname/ 0 0 0
1503 0 ▶ return 'not-yet-valid' if $error =~ /not yet valid/;
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /not yet valid/ 0 0 0
1504 0 ▶ return 'expired' if $error =~ /expired/;
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /expired/ 0 0 0
1505 0 ▶ return 'untrusted-root'
Branch: 1 branch
BranchTrueFalseTotal
if $error =~ /unable to get/ or $error =~ /self[- ]signed/ or $error =~ /unable to verify/ or $error =~ /issuer certificate/ 0 0 0
Condition0%0/9
$error =~ /unable to get/ or $error =~ /self[- ]signed/ or $error =~ /unable to verify/ or $error =~ /issuer certificate/
l!l&&r!l&&!r
000
$error =~ /unable to get/ or $error =~ /self[- ]signed/ or $error =~ /unable to verify/
l!l&&r!l&&!r
000
$error =~ /unable to get/ or $error =~ /self[- ]signed/
l!l&&r!l&&!r
000
MC/DC0%0/4
$error =~ /unable to get/ or $error =~ /self[- ]signed/ or $error =~ /unable to verify/ or $error =~ /issuer certificate/
$error =~ /unable to get/ $error =~ /self[- ]signed/ $error =~ /unable to verify/ $error =~ /issuer certificate/
Truth table0%0/5
A or B or C or D
A= $error =~ /unable to get/B= $error =~ /self[- ]signed/C= $error =~ /unable to verify/D= $error =~ /issuer certificate/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1506 if $error =~ /unable to get/
1507 or $error =~ /self[- ]signed/
1508 or $error =~ /unable to verify/
1509 or $error =~ /issuer certificate/;
1510 0 return 'invalid-chain';
1511 }
1512  
1513 0 ▶sub _certificate_verify_result {
Subroutine _certificate_verify_result: not called CC=2 SCAR=17.9
1514 0 my ( %result ) = @_;
1515  
1516 return Zuzu::Value::Dict->new(
1517 map => {
1518 valid => $result{valid} ? _true() : _false(),
1519 reason => $result{reason},
1520 error => $result{error},
1521 hostname => $result{hostname},
1522 verified_at => $result{verified_at},
1523 chain_length => $result{chain_length},
1524 },
1525 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$result{'valid'} ? : 0 0 0
1526 }
1527  
1528 0 ▶sub _certificate_verify_chain {
Subroutine _certificate_verify_chain: not called CC=14 SCAR=53.5
1529 0 my ( $chain_value, $options_value ) = @_;
1530  
1531 0 my $label = 'Certificate.verify_chain';
1532 0 my @chain = _certificate_array_arg( $chain_value, $label );
1533 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
1534 my $hostname = defined $options->{hostname}
1535 0 ▶ ? _string_arg( $options->{hostname}, $label, 'String hostname' )
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'hostname'} ? : 0 0 0
1536 : undef;
1537 0 my $verified_at = _certificate_time_option( $options->{time}, $label );
1538 my $use_system_roots = _certificate_bool_option(
1539 $options->{use_system_roots},
1540 0 $label,
1541 'use_system_roots',
1542 0,
1543 );
1544 0 my @root_ders = _certificate_root_ders( $options->{roots}, $label );
1545  
1546 0 my $ctx_owner;
1547 my $store;
1548 0 ▶ if ($use_system_roots) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_system_roots) { } 0 0 0
1549 0 $ctx_owner = Net::SSLeay::CTX_new();
1550 0 ▶ _error( "$label failed to initialize system trust store" )
Branch: 1 branch
BranchTrueFalseTotal
unless $ctx_owner 0 0 0
1551 if not $ctx_owner;
1552 0 Net::SSLeay::CTX_set_default_verify_paths($ctx_owner);
1553 0 $store = Net::SSLeay::CTX_get_cert_store($ctx_owner);
1554 }
1555 else {
1556 0 $store = Net::SSLeay::X509_STORE_new();
1557 }
1558 0 ▶ _error( "$label failed to initialize trust store" )
Branch: 1 branch
BranchTrueFalseTotal
unless $store 0 0 0
1559 if not $store;
1560  
1561 0 my $param = Net::SSLeay::X509_VERIFY_PARAM_new();
1562 0 Net::SSLeay::X509_VERIFY_PARAM_set_time( $param, $verified_at );
1563 0 ▶ Net::SSLeay::X509_VERIFY_PARAM_set1_host( $param, $hostname )
Branch: 1 branch
BranchTrueFalseTotal
if defined $hostname 0 0 0
1564 if defined $hostname;
1565 0 Net::SSLeay::X509_STORE_set1_param( $store, $param );
1566  
1567 0 my @owned_x509;
1568 0 for my $root_der ( @root_ders ) {
1569 0 my $root = _certificate_net_x509( $root_der, $label );
1570 0 push @owned_x509, $root;
1571 0 Net::SSLeay::X509_STORE_add_cert( $store, $root );
1572 }
1573  
1574 0 my ( $leaf_der ) = _certificate_state( $chain[0], $label );
1575 0 my $leaf = _certificate_net_x509( $leaf_der, $label );
1576 0 push @owned_x509, $leaf;
1577 0 my $extra_chain = Net::SSLeay::sk_X509_new_null();
1578 0 for my $cert ( @chain[ 1 .. $#chain ] ) {
1579 0 my ( $der ) = _certificate_state( $cert, $label );
1580 0 my $intermediate = _certificate_net_x509( $der, $label );
1581 0 push @owned_x509, $intermediate;
1582 0 Net::SSLeay::sk_X509_push(
1583 $extra_chain,
1584 $intermediate,
1585 );
1586 }
1587  
1588 0 my $store_ctx = Net::SSLeay::X509_STORE_CTX_new();
1589 0 Net::SSLeay::X509_STORE_CTX_init(
1590 $store_ctx,
1591 $store,
1592 $leaf,
1593 $extra_chain,
1594 );
1595 0 ▶ my $ok = Net::SSLeay::X509_verify_cert($store_ctx) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&Net::SSLeay::X509_verify_cert($store_ctx) ? : 0 0 0
1596 0 my $error_code = Net::SSLeay::X509_STORE_CTX_get_error($store_ctx);
1597 0 ▶ my $error = $ok
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
1598 ? undef
1599 : Net::SSLeay::X509_verify_cert_error_string($error_code);
1600 0 ▶ my $reason = $ok ? 'ok' : _certificate_verify_reason($error);
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
1601  
1602 0 Net::SSLeay::X509_STORE_CTX_free($store_ctx);
1603 0 Net::SSLeay::sk_X509_free($extra_chain);
1604 0 Net::SSLeay::X509_free($_) for @owned_x509;
1605 0 Net::SSLeay::X509_VERIFY_PARAM_free($param);
1606 0 ▶ Net::SSLeay::CTX_free($ctx_owner) if $ctx_owner;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx_owner 0 0 0
1607 0 ▶ Net::SSLeay::X509_STORE_free($store) if not $ctx_owner;
Branch: 1 branch
BranchTrueFalseTotal
unless $ctx_owner 0 0 0
1608  
1609 0 return _certificate_verify_result(
1610 valid => $ok,
1611 reason => $reason,
1612 error => $error,
1613 hostname => $hostname,
1614 verified_at => $verified_at,
1615 chain_length => scalar @chain,
1616 );
1617 }
1618  
1619 0 ▶sub _certificate_time {
Subroutine _certificate_time: not called CC=5 SCAR=34.0
1620 0 my ( $time_class, $self, $method, $value ) = @_;
1621  
1622 0 my ( $mon_name, $day, $hour, $minute, $second, $year, $zone )
1623 = $value =~ /\A([A-Z][a-z]{2})\s+(\d{1,2})\s+(\d\d):(\d\d):(\d\d)\s+(\d{4})\s+([A-Z]+)\z/;
1624 0 ▶ _error( "$method returned unrecognised certificate time '$value'" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mon_name 0 0 0
1625 if not defined $mon_name;
1626 0 ▶ _error( "$method returned unsupported certificate time zone '$zone'" )
Branch: 1 branch
BranchTrueFalseTotal
if $zone ne "GMT" and $zone ne "UTC" 0 0 0
Condition0%0/3
$zone ne "GMT" and $zone ne "UTC"
!ll&&!rl&&r
000
MC/DC0%0/2
$zone ne "GMT" and $zone ne "UTC"
$zone ne "GMT" $zone ne "UTC"
Truth table0%0/3
A and B
A= $zone ne "GMT"B= $zone ne "UTC"
ABresult
0X0
100
111
1627 if $zone ne 'GMT' and $zone ne 'UTC';
1628  
1629 my $dt = DateTime::Lite->new(
1630 year => 0 + $year,
1631 0 month => $CERTIFICATE_TIME_MONTH{$mon_name},
1632 day => 0 + $day,
1633 hour => 0 + $hour,
1634 minute => 0 + $minute,
1635 second => 0 + $second,
1636 time_zone => '+0000',
1637 );
1638 0 ▶ _error( "$method returned invalid certificate time '$value'" )
Branch: 1 branch
BranchTrueFalseTotal
unless $dt 0 0 0
1639 if not $dt;
1640  
1641 0 return native_object(
1642 class => $time_class,
1643 slots => {
1644 _epoch => $dt->epoch,
1645 },
1646 const => {
1647 _epoch => 1,
1648 },
1649 );
1650 }
1651  
1652 0 ▶sub _certificate_fingerprint {
Subroutine _certificate_fingerprint: not called CC=3 SCAR=24.8
1653 0 my ( $self, $algorithm ) = @_;
1654  
1655 0 my ( $der ) = _certificate_state( $self, 'Certificate.fingerprint' );
1656 0 ▶ $algorithm = 'sha256' if not defined $algorithm;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $algorithm 0 0 0
1657 0 my %digests = (
1658 sha256 => \&sha256,
1659 sha384 => \&sha384,
1660 sha512 => \&sha512,
1661 );
1662 0 my $digest = $digests{ lc("$algorithm") };
1663 0 ▶ _error( "Certificate.fingerprint algorithm '$algorithm' is not available" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $digest 0 0 0
1664 if not defined $digest;
1665 0 return Zuzu::Value::BinaryString->new( bytes => $digest->($der) );
1666 }
1667  
1668 0 ▶sub _certificate_public_key {
Subroutine _certificate_public_key: not called CC=12 SCAR=50.5
1669 0 my ( $public_key_class, $self ) = @_;
1670  
1671 0 my ( undef, $x509 ) = _certificate_state( $self, 'Certificate.public_key' );
1672 0 my $pem = $x509->pubkey;
1673 0 ▶ my $curve = eval { $x509->curve } // '';
Condition0%0/2
eval { do { $x509->curve } } // ""
l!l
00
MC/DC0%0/1
eval { do { $x509->curve } } // ""
eval { do { $x509->curve } }
Truth table0%0/2
A
A= eval { do { $x509->curve } }
Aresult
11
00
1674 0 my ( $algorithm, $pk );
1675 0 ▶ if ( ( $x509->pubkey_type // '' ) eq 'ec' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($x509->pubkey_type // '') eq 'ec') { } 0 0 0
elsif (($x509->pubkey_type // '') eq 'ed25519') { } 0 0 0
Condition0%0/2
$x509->pubkey_type // ""
l!l
00
MC/DC0%0/1
$x509->pubkey_type // ""
$x509->pubkey_type
Truth table0%0/2
A
A= $x509->pubkey_type
Aresult
11
00
1676 0 ▶ $algorithm = $curve eq 'prime256v1'
Branch: 3 branches
BranchTrueFalseTotal
$curve eq 'prime256v1' ? : 0 0 0
$curve eq 'secp384r1' ? : 0 0 0
$curve eq 'secp521r1' ? : 0 0 0
1677 ? 'ecdsa-p256-sha256'
1678 : $curve eq 'secp384r1'
1679 ? 'ecdsa-p384-sha384'
1680 : $curve eq 'secp521r1'
1681 ? 'ecdsa-p521-sha512'
1682 : undef;
1683 0 ▶ _error(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $algorithm 0 0 0
1684 'Certificate.public_key certificate public-key algorithm '
1685 . 'is unsupported',
1686 ) if not defined $algorithm;
1687 0 $pk = Crypt::PK::ECC->new;
1688 _error( 'Certificate.public_key failed to import public key' )
1689 0 ▶ if not eval { $pk->import_key( \$pem ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pk->import_key(\$pem); 1 } } 0 0 0
1690 }
1691 ▶ elsif ( ( $x509->pubkey_type // '' ) eq 'ed25519' ) {
Condition0%0/2
$x509->pubkey_type // ""
l!l
00
MC/DC0%0/1
$x509->pubkey_type // ""
$x509->pubkey_type
Truth table0%0/2
A
A= $x509->pubkey_type
Aresult
11
00
1692 0 $algorithm = 'ed25519';
1693 0 $pk = Crypt::PK::Ed25519->new;
1694 _error( 'Certificate.public_key failed to import public key' )
1695 0 ▶ if not eval { $pk->import_key( \$pem ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pk->import_key(\$pem); 1 } } 0 0 0
1696 }
1697 else {
1698 0 _error(
1699 'Certificate.public_key certificate public-key algorithm '
1700 . 'is unsupported',
1701 );
1702 }
1703 0 return _new_public_key( $public_key_class, $algorithm, $pk );
1704 }
1705  
1706 1 ▶sub _new_tls_identity {
Subroutine _new_tls_identity: called CC=1 SCAR=0.0
1707 1 my ( $tls_identity_class, %slots ) = @_;
1708  
1709 1 return native_object(
1710 class => $tls_identity_class,
1711 slots => \%slots,
1712 const => {
1713 _cert_pem => 1,
1714 _key_pem => 1,
1715 _password => 1,
1716 _chain_pem => 1,
1717 _source => 1,
1718 },
1719 );
1720 }
1721  
1722 0 ▶sub _tls_identity_state {
Subroutine _tls_identity_state: not called CC=4 SCAR=30.0
1723 0 my ( $self, $label ) = @_;
1724  
1725 0 ▶ _error( "TypeException: $label expects TlsIdentity" )
Branch: 1 branch
BranchTrueFalseTotal
if not builtin::blessed($self) && $self->can("class") or $self->class->name ne "TlsIdentity" 0 0 0
Condition0%0/6
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "TlsIdentity"
l!l&&r!l&&!r
000
builtin::blessed($self) && $self->can('class')
!ll&&!rl&&r
000
MC/DC0%0/3
not builtin::blessed($self) && $self->can("class") or $self->class->name ne "TlsIdentity"
builtin::blessed($self) $self->can('class') $self->class->name ne "TlsIdentity"
Truth table0%0/4
not(A && B) or C
A= builtin::blessed($self)B= $self->can('class')C= $self->class->name ne "TlsIdentity"
ABCresult
0XX1
10X1
1111
1100
1726 if not blessed($self)
1727 or not $self->can('class')
1728 or $self->class->name ne 'TlsIdentity';
1729 0 return $self->slots;
1730 }
1731  
1732 1 ▶sub _tls_identity_from_pem {
Subroutine _tls_identity_from_pem: called CC=2 SCAR=6.9
1733 1 my ( $tls_identity_class, $certificate_pem, $private_key_pem, $password ) = @_;
1734  
1735 1 my $label = 'TlsIdentity.from_pem';
1736 1 my $cert_pem = _string_arg(
1737 $certificate_pem,
1738 $label,
1739 'String certificate_pem',
1740 );
1741 1 my $key_pem = _string_arg(
1742 $private_key_pem,
1743 $label,
1744 'String private_key_pem',
1745 );
1746 1 my $pass = _optional_password_text( $password, $label, 'String password' );
1747 1 my @blocks = _pem_blocks( $cert_pem, $label );
1748 1 _parse_x509_der( native_class( name => 'Certificate' ), $blocks[0], $label );
1749 1 ▶ _error( "$label expects PEM private key text" )
Branch: 1 branch
BranchTrueFalseTotal
unless $key_pem =~ /-----BEGIN [A-Z ]*PRIVATE KEY-----/ 0 1 1
1750 if $key_pem !~ /-----BEGIN [A-Z ]*PRIVATE KEY-----/;
1751  
1752 return _new_tls_identity(
1753 $tls_identity_class,
1754 _cert_pem => _der_to_pem_certificate( $blocks[0] ),
1755 _key_pem => $key_pem,
1756 _password => $pass,
1757 1 _chain_pem => join( '', map { _der_to_pem_certificate($_) } @blocks ),
1758 _source => 'pem',
1759 );
1760 }
1761  
1762 0 ▶sub _tls_identity_from_pkcs12 {
Subroutine _tls_identity_from_pkcs12: not called CC=6 SCAR=37.4
1763 0 my ( $tls_identity_class, $bytes_value, $password ) = @_;
1764  
1765 0 my $label = 'TlsIdentity.from_pkcs12';
1766 0 my $bytes = _binary_bytes( $bytes_value, $label, 'BinaryString bytes' );
1767 0 my $pass = _optional_password_text( $password, $label, 'String password' );
1768 0 my $pkcs12 = eval { Crypt::OpenSSL::PKCS12->new_from_string($bytes) };
1769 0 ▶ _error( "$label expects PKCS#12 data" ) if not defined $pkcs12;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkcs12 0 0 0
1770 _error( "$label failed to decrypt PKCS#12 data" )
1771 0 ▶ if not eval { $pkcs12->mac_ok($pass) };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pkcs12->mac_ok($pass) } } 0 0 0
1772 0 my $cert_pem = eval { $pkcs12->certificate($pass) };
1773 0 my $key_pem = eval { $pkcs12->private_key($pass) };
1774 0 ▶ _error( "$label expects PKCS#12 data with certificate and private key" )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cert_pem and defined $key_pem 0 0 0
Condition0%0/3
defined $cert_pem and defined $key_pem
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cert_pem and defined $key_pem
defined $cert_pem defined $key_pem
Truth table0%0/3
A and B
A= defined $cert_pemB= defined $key_pem
ABresult
0X0
100
111
1775 if not defined $cert_pem or not defined $key_pem;
1776 0 ▶ my $ca_pem = eval { $pkcs12->ca_certificate($pass) } // '';
Condition0%0/2
eval { do { $pkcs12->ca_certificate($pass) } } // ""
l!l
00
MC/DC0%0/1
eval { do { $pkcs12->ca_certificate($pass) } } // ""
eval { do { $pkcs12->ca_certificate($pass) } }
Truth table0%0/2
A
A= eval { do { $pkcs12->ca_certificate($pass) } }
Aresult
11
00
1777 0 my @blocks = _pem_blocks( $cert_pem, $label );
1778  
1779 0 return _new_tls_identity(
1780 $tls_identity_class,
1781 _cert_pem => _der_to_pem_certificate( $blocks[0] ),
1782 _key_pem => $key_pem,
1783 _password => '',
1784 _chain_pem => $cert_pem . $ca_pem,
1785 _source => 'pkcs12',
1786 );
1787 }
1788  
1789 0 ▶sub _tls_identity_certificate {
Subroutine _tls_identity_certificate: not called CC=1 SCAR=6.9
1790 0 my ( $certificate_class, $self ) = @_;
1791  
1792 0 my $state = _tls_identity_state( $self, 'TlsIdentity.certificate' );
1793 0 my ( $der ) = _pem_blocks( $state->{_cert_pem}, 'TlsIdentity.certificate' );
1794 0 return _parse_x509_der( $certificate_class, $der, 'TlsIdentity.certificate' );
1795 }
1796  
1797 0 ▶sub _tls_identity_private_key {
Subroutine _tls_identity_private_key: not called CC=2 SCAR=17.9
1798 0 my ( $signing_key_class, $self ) = @_;
1799  
1800 0 my $state = _tls_identity_state( $self, 'TlsIdentity.private_key' );
1801 my $options = Zuzu::Value::Dict->new(
1802 map => {
1803 format => 'pem',
1804 password => $state->{_password},
1805 },
1806 0 );
1807 return eval {
1808 _signing_import_private(
1809 $signing_key_class,
1810 $state->{_key_pem},
1811 0 $options,
1812 );
1813 0 ▶ } // do {
Condition0%0/3
eval { do { _signing_import_private($signing_key_class, $state->{"_key_pem"}, $options) } } // do { _error("TlsIdentity.private_key only supports Ed25519, ECDSA P-256, ECDSA P-384, and ECDSA P-521 private keys") }
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { _signing_import_private($signing_key_class, $state->{"_key_pem"}, $options) } } // do { _error("TlsIdentity.private_key only supports Ed25519, ECDSA P-256, ECDSA P-384, and ECDSA P-521 private keys") }
eval { do { _signing_import_private($signing_key_class, $state->{"_key_pem"}, $options) } } do { _error("TlsIdentity.private_key only supports Ed25519, ECDSA P-256, ECDSA P-384, and ECDSA P-521 private keys") }
Truth table0%0/3
A // B
A= eval { do { _signing_import_private($signing_key_class, $state->{"_key_pem"}, $options) } }B= do { _error("TlsIdentity.private_key only supports Ed25519, ECDSA P-256, ECDSA P-384, and ECDSA P-521 private keys") }
ABresult
1X1
011
000
1814 0 _error(
1815 'TlsIdentity.private_key only supports Ed25519, ECDSA P-256, '
1816 . 'ECDSA P-384, and ECDSA P-521 private keys',
1817 );
1818 };
1819 }
1820  
1821 0 ▶sub _signing_generate {
Subroutine _signing_generate: not called CC=3 SCAR=24.8
1822 0 my ( $signing_key_class, $algorithm ) = @_;
1823  
1824 0 my $label = 'SigningKey.generate';
1825 0 $algorithm = _signing_algorithm( $algorithm, $label );
1826 0 my $meta = _signing_meta($algorithm);
1827 0 my $pk = _new_key_for_algorithm($algorithm);
1828 0 ▶ if ( $meta->{type} eq 'ed25519' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($meta->{'type'} eq 'ed25519') { } 0 0 0
elsif ($meta->{'type'} eq 'ecdsa') { } 0 0 0
1829 0 $pk->generate_key;
1830 }
1831 elsif ( $meta->{type} eq 'ecdsa' ) {
1832 0 $pk->generate_key( $meta->{curve} );
1833 }
1834 0 return _new_signing_key( $signing_key_class, $algorithm, $pk );
1835 }
1836  
1837 0 ▶sub _signing_import_private {
Subroutine _signing_import_private: not called CC=12 SCAR=50.5
1838 0 my ( $signing_key_class, $key, $options ) = @_;
1839  
1840 0 my $label = 'SigningKey.import_private';
1841 0 my $opts = _signing_options( $options, $label );
1842 0 my $format = _key_format( $options, $key, $label );
1843 0 my $algorithm = _signing_algorithm_option( $opts, $label );
1844 my $password = exists $opts->{password}
1845 ? _optional_password_text(
1846 $opts->{password},
1847 0 ▶ $label,
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'password'} ? : 0 0 0
1848 'String options.password',
1849 )
1850 : undef;
1851 0 my $pk;
1852 0 ▶ if ( $format eq 'raw' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($format eq 'raw') { } 0 0 0
elsif ($format eq 'pem') { } 0 0 0
1853 0 my $bytes = _binary_bytes( $key, $label, 'BinaryString key' );
1854 0 ▶ $algorithm //= 'ed25519';
Condition0%0/2
$algorithm //= "ed25519"
l!l
00
MC/DC0%0/1
$algorithm //= "ed25519"
$algorithm
Truth table0%0/2
A
A= $algorithm
Aresult
11
00
1855 0 my $meta = _signing_meta($algorithm);
1856 _error( "$label expects a $meta->{private_length}-byte raw private key" )
1857 0 ▶ if length($bytes) != $meta->{private_length};
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes != $meta->{"private_length"} 0 0 0
1858 0 $pk = _new_key_for_algorithm($algorithm);
1859 0 ▶ if ( $meta->{type} eq 'ed25519' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{'type'} eq 'ed25519') { } 0 0 0
1860 0 $pk->import_key_raw( $bytes, 'private' );
1861 }
1862 else {
1863 0 $pk->import_key_raw( $bytes, $meta->{curve} );
1864 }
1865 }
1866 elsif ( $format eq 'pem' ) {
1867 0 my $pem = _string_arg( $key, $label, 'String key' );
1868 0 ▶ if ( defined $algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $algorithm) { } 0 0 0
1869 0 $pk = _new_key_for_algorithm($algorithm);
1870 _error( "$label expects PEM private key" )
1871 0 ▶ if not eval { $pk->import_key( \$pem, $password ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pk->import_key(\$pem, $password); 1 } } 0 0 0
1872 0 ▶ if ( _signing_meta($algorithm)->{type} eq 'ecdsa' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_signing_meta($algorithm)->{"type"} eq "ecdsa") 0 0 0
1873 0 my $actual = _ecdsa_algorithm_for_key( $pk, $label );
1874 0 ▶ _error( "$label PEM key algorithm does not match $algorithm" )
Branch: 1 branch
BranchTrueFalseTotal
if $actual ne $algorithm 0 0 0
1875 if $actual ne $algorithm;
1876 }
1877 }
1878 else {
1879 0 $pk = Crypt::PK::Ed25519->new;
1880 0 ▶ if ( not eval { $pk->import_key( \$pem, $password ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not eval { do { $pk->import_key(\$pem, $password); 1 } }) { } 0 0 0
1881 0 $pk = Crypt::PK::ECC->new;
1882 0 $pk->import_key( \$pem, $password );
1883 0 $algorithm = _ecdsa_algorithm_for_key( $pk, $label );
1884 }
1885 else {
1886 0 $algorithm = 'ed25519';
1887 }
1888 }
1889 }
1890 else {
1891 0 _error( "$label only supports raw and pem formats" );
1892 }
1893  
1894 0 return _new_signing_key( $signing_key_class, $algorithm, $pk );
1895 }
1896  
1897 0 ▶sub _signing_import_public {
Subroutine _signing_import_public: not called CC=14 SCAR=53.5
1898 0 my ( $public_key_class, $key, $options ) = @_;
1899  
1900 0 my $label = 'SigningKey.import_public';
1901 0 my $opts = _signing_options( $options, $label );
1902 0 my $format = _key_format( $options, $key, $label );
1903 0 my $algorithm = _signing_algorithm_option( $opts, $label );
1904 0 my $pk;
1905 0 ▶ if ( $format eq 'raw' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($format eq 'raw') { } 0 0 0
elsif ($format eq 'pem') { } 0 0 0
1906 0 my $bytes = _binary_bytes( $key, $label, 'BinaryString key' );
1907 0 ▶ if ( defined $algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $algorithm) { } 0 0 0
1908 0 my $meta = _signing_meta($algorithm);
1909 _error( "$label expects a $meta->{public_length}-byte raw public key" )
1910 0 ▶ if length($bytes) != $meta->{public_length};
Branch: 1 branch
BranchTrueFalseTotal
if length $bytes != $meta->{"public_length"} 0 0 0
1911 }
1912 else {
1913 0 ▶ $algorithm = length($bytes) == 32
Branch: 1 branch
BranchTrueFalseTotal
length $bytes == 32 ? : 0 0 0
1914 ? 'ed25519'
1915 : _ecdsa_algorithm_for_public_length( length($bytes), $label );
1916 }
1917 0 my $meta = _signing_meta($algorithm);
1918 0 ▶ if ( $meta->{type} eq 'ecdsa' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"type"} eq "ecdsa") 0 0 0
1919 0 ▶ _error( "$label expects an uncompressed EC public key" )
Branch: 1 branch
BranchTrueFalseTotal
if substr($bytes, 0, 1) ne "\4" 0 0 0
1920 if substr( $bytes, 0, 1 ) ne "\x04";
1921 }
1922 0 $pk = _new_key_for_algorithm($algorithm);
1923 0 ▶ if ( $meta->{type} eq 'ed25519' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{'type'} eq 'ed25519') { } 0 0 0
1924 0 $pk->import_key_raw( $bytes, 'public' );
1925 }
1926 else {
1927 0 $pk->import_key_raw( $bytes, $meta->{curve} );
1928 }
1929 }
1930 elsif ( $format eq 'pem' ) {
1931 0 my $pem = _string_arg( $key, $label, 'String key' );
1932 0 ▶ if ( defined $algorithm ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $algorithm) { } 0 0 0
1933 0 $pk = _new_key_for_algorithm($algorithm);
1934 _error( "$label expects PEM public key" )
1935 0 ▶ if not eval { $pk->import_key( \$pem ); 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $pk->import_key(\$pem); 1 } } 0 0 0
1936 0 ▶ if ( _signing_meta($algorithm)->{type} eq 'ecdsa' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_signing_meta($algorithm)->{"type"} eq "ecdsa") 0 0 0
1937 0 my $actual = _ecdsa_algorithm_for_key( $pk, $label );
1938 0 ▶ _error( "$label PEM key algorithm does not match $algorithm" )
Branch: 1 branch
BranchTrueFalseTotal
if $actual ne $algorithm 0 0 0
1939 if $actual ne $algorithm;
1940 }
1941 }
1942 else {
1943 0 $pk = Crypt::PK::Ed25519->new;
1944 0 ▶ if ( not eval { $pk->import_key( \$pem ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not eval { do { $pk->import_key(\$pem); 1 } }) { } 0 0 0
1945 0 $pk = Crypt::PK::ECC->new;
1946 0 $pk->import_key( \$pem );
1947 0 $algorithm = _ecdsa_algorithm_for_key( $pk, $label );
1948 }
1949 else {
1950 0 $algorithm = 'ed25519';
1951 }
1952 }
1953 }
1954 else {
1955 0 _error( "$label only supports raw and pem formats" );
1956 }
1957  
1958 0 return _new_public_key( $public_key_class, $algorithm, $pk );
1959 }
1960  
1961 0 ▶sub _signing_public_key {
Subroutine _signing_public_key: not called CC=2 SCAR=17.9
1962 0 my ( $public_key_class, $self ) = @_;
1963  
1964 0 my ( $algorithm, $pk ) = _signing_private_state(
1965 $self,
1966 'SigningKey.public_key',
1967 );
1968 0 my $meta = _signing_meta($algorithm);
1969 0 my $public = _new_key_for_algorithm($algorithm);
1970 0 my $raw = $pk->export_key_raw('public');
1971 0 ▶ if ( $meta->{type} eq 'ed25519' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{'type'} eq 'ed25519') { } 0 0 0
1972 0 $public->import_key_raw( $raw, 'public' );
1973 }
1974 else {
1975 0 $public->import_key_raw( $raw, $meta->{curve} );
1976 }
1977 0 return _new_public_key( $public_key_class, $algorithm, $public );
1978 }
1979  
1980 0 ▶sub _signing_sign {
Subroutine _signing_sign: not called CC=2 SCAR=17.9
1981 0 my ( $self, $message ) = @_;
1982  
1983 0 my ( $algorithm, $pk ) = _signing_private_state( $self, 'SigningKey.sign' );
1984 0 my $bytes = _binary_bytes(
1985 $message,
1986 'SigningKey.sign',
1987 'BinaryString message',
1988 );
1989 0 my $meta = _signing_meta($algorithm);
1990 my $signature = $meta->{type} eq 'ed25519'
1991 ? $pk->sign_message($bytes)
1992 0 ▶ : $pk->sign_message( $bytes, $meta->{hash} );
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'type'} eq 'ed25519' ? : 0 0 0
1993 0 return Zuzu::Value::BinaryString->new(
1994 bytes => $signature,
1995 );
1996 }
1997  
1998 0 ▶sub _signing_export_private {
Subroutine _signing_export_private: not called CC=4 SCAR=30.0
1999 0 my ( $self, $options_value ) = @_;
2000  
2001 0 my $label = 'SigningKey.export_private';
2002 0 my ( $algorithm, $pk ) = _signing_private_state( $self, $label );
2003 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
2004 0 ▶ my $format = defined $options->{format} ? "$options->{format}" : 'raw';
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'format'} ? : 0 0 0
2005 0 ▶ return Zuzu::Value::BinaryString->new(
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "raw" 0 0 0
2006 bytes => $pk->export_key_raw('private'),
2007 ) if $format eq 'raw';
2008 0 ▶ return $pk->export_key_pem('private') if $format eq 'pem';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "pem" 0 0 0
2009 0 _error( "$label only supports raw and pem formats" );
2010 }
2011  
2012 0 ▶sub _public_key_verify {
Subroutine _public_key_verify: not called CC=5 SCAR=34.0
2013 0 my ( $self, $message, $signature ) = @_;
2014  
2015 0 my ( $algorithm, $pk ) = _signing_public_state( $self, 'PublicKey.verify' );
2016 0 my $message_bytes = _binary_bytes(
2017 $message,
2018 'PublicKey.verify',
2019 'BinaryString message',
2020 );
2021 0 my $signature_bytes = _binary_bytes(
2022 $signature,
2023 'PublicKey.verify',
2024 'BinaryString signature',
2025 );
2026 0 my $meta = _signing_meta($algorithm);
2027 return _false()
2028 0 ▶ if $meta->{type} eq 'ed25519' and length($signature_bytes) != 64;
Branch: 1 branch
BranchTrueFalseTotal
if $meta->{"type"} eq "ed25519" and length $signature_bytes != 64 0 0 0
Condition0%0/3
$meta->{"type"} eq "ed25519" and length $signature_bytes != 64
!ll&&!rl&&r
000
MC/DC0%0/2
$meta->{"type"} eq "ed25519" and length $signature_bytes != 64
$meta->{"type"} eq "ed25519" length $signature_bytes != 64
Truth table0%0/3
A and B
A= $meta->{"type"} eq "ed25519"B= length $signature_bytes != 64
ABresult
0X0
100
111
2029 my $valid = $meta->{type} eq 'ed25519'
2030 0 ? eval { $pk->verify_message( $signature_bytes, $message_bytes ) }
2031 0 ▶ : eval {
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'type'} eq 'ed25519' ? : 0 0 0
2032 $pk->verify_message(
2033 $signature_bytes,
2034 $message_bytes,
2035 $meta->{hash},
2036 0 );
2037 };
2038 0 ▶ return $valid
Branch: 1 branch
BranchTrueFalseTotal
$valid ? : 0 0 0
2039 ? _true()
2040 : _false();
2041 }
2042  
2043 0 ▶sub _public_key_export {
Subroutine _public_key_export: not called CC=5 SCAR=34.0
2044 0 my ( $self, $options_value ) = @_;
2045  
2046 0 my $label = 'PublicKey.export';
2047 0 my ( $algorithm, $pk ) = _public_key_state( $self, $label );
2048 0 my $options = _optional_dict_map( $options_value, $label, 'Dict options' );
2049 0 ▶ my $format = defined $options->{format} ? "$options->{format}" : 'raw';
Branch: 1 branch
BranchTrueFalseTotal
defined $options->{'format'} ? : 0 0 0
2050 0 ▶ return Zuzu::Value::BinaryString->new(
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "raw" 0 0 0
2051 bytes => $pk->export_key_raw('public'),
2052 ) if $format eq 'raw';
2053 0 ▶ _error( "$label only supports raw format for x25519 public keys" )
Branch: 1 branch
BranchTrueFalseTotal
if $algorithm eq "x25519" 0 0 0
2054 if $algorithm eq 'x25519';
2055 0 ▶ return $pk->export_key_pem('public') if $format eq 'pem';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "pem" 0 0 0
2056 0 _error( "$label only supports raw and pem formats" );
2057 }
2058  
2059 0 ▶sub _hkdf_sha256 {
Subroutine _hkdf_sha256: not called CC=3 SCAR=24.8
2060 0 my ( $input_key_material, $length, $salt, $info ) = @_;
2061  
2062 0 my $label = 'KeyDerivation.hkdf_sha256';
2063 0 my $ikm = _binary_bytes( $input_key_material, $label );
2064 0 $length = _hkdf_length( $length, $label );
2065 0 $salt = _optional_binary_bytes( $salt, $label, 'BinaryString salt' );
2066 0 $info = _optional_binary_bytes( $info, $label, 'BinaryString info' );
2067  
2068 0 ▶ return Zuzu::Value::BinaryString->new( bytes => '' ) if $length == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $length == 0 0 0 0
2069  
2070 0 my $prk = hmac_sha256( $ikm, $salt );
2071 0 my $previous = '';
2072 0 my $out = '';
2073 0 my $counter = 1;
2074 0 ▶ while ( length($out) < $length ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $out < $length) 0 0 0
2075 0 $previous = hmac_sha256(
2076 $previous . $info . chr($counter),
2077 $prk,
2078 );
2079 0 $out .= $previous;
2080 0 $counter++;
2081 }
2082  
2083 0 return Zuzu::Value::BinaryString->new(
2084 bytes => substr( $out, 0, $length ),
2085 );
2086 }
2087  
2088 0 ▶sub _random_bytes {
Subroutine _random_bytes: not called CC=1 SCAR=6.9
2089 0 my ( $length ) = @_;
2090  
2091 0 return Zuzu::Value::BinaryString->new(
2092 bytes => urandom($length),
2093 );
2094 }
2095  
2096 0 ▶sub _base64url {
Subroutine _base64url: not called CC=6 SCAR=37.4
2097 0 my ( $bytes ) = @_;
2098  
2099 0 my $out = '';
2100 0 my $i = 0;
2101 0 my $len = length($bytes);
2102 0 ▶ while ( $i < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
2103 0 my $b0 = ord( substr( $bytes, $i, 1 ) );
2104 0 ▶ my $b1 = $i + 1 < $len ? ord( substr( $bytes, $i + 1, 1 ) ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i + 1 < $len ? : 0 0 0
2105 0 ▶ my $b2 = $i + 2 < $len ? ord( substr( $bytes, $i + 2, 1 ) ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i + 2 < $len ? : 0 0 0
2106 0 my $triple = ( $b0 << 16 ) | ( $b1 << 8 ) | $b2;
2107  
2108 0 $out .= $BASE64URL[ ( $triple >> 18 ) & 0x3f ];
2109 0 $out .= $BASE64URL[ ( $triple >> 12 ) & 0x3f ];
2110 0 ▶ $out .= $BASE64URL[ ( $triple >> 6 ) & 0x3f ]
Branch: 1 branch
BranchTrueFalseTotal
if $i + 1 < $len 0 0 0
2111 if $i + 1 < $len;
2112 0 ▶ $out .= $BASE64URL[ $triple & 0x3f ]
Branch: 1 branch
BranchTrueFalseTotal
if $i + 2 < $len 0 0 0
2113 if $i + 2 < $len;
2114  
2115 0 $i += 3;
2116 }
2117  
2118 0 return $out;
2119 }
2120  
2121 0 ▶sub _random_int {
Subroutine _random_int: not called CC=3 SCAR=24.8
2122 0 my ( $max ) = @_;
2123  
2124 0 ▶ return 0 if $max == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $max == 1 0 0 0
2125  
2126 0 my $limit = $RANDOM_INT_SPACE - ( $RANDOM_INT_SPACE % $max );
2127 0 while (1) {
2128 0 my $value = unpack( 'Q>', "\0" . urandom(7) );
2129 0 ▶ return $value % $max if $value < $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $value < $limit 0 0 0
2130 }
2131 }
2132  
2133 5 ▶sub IMPORT {
Subroutine IMPORT: called CC=1 SCAR=5.2
Pod undocumented
2134 5 my ( $class, $runtime ) = @_;
2135  
2136 my $secure_class = native_class(
2137 name => 'Secure',
2138 static_methods => {
2139 capabilities => native_function(
2140 name => 'capabilities',
2141 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2142 0 return _capabilities();
2143 },
2144 ),
2145 has => native_function(
2146 name => 'has',
2147 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2148 0 my ( $self, $area, $name ) = @_;
2149 0 ▶ return _has_capability( $area, $name )
Branch: 1 branch
BranchTrueFalseTotal
_has_capability($area, $name) ? : 0 0 0
2150 ? _true()
2151 : _false();
2152 },
2153 ),
2154 require => native_function(
2155 name => 'require',
2156 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2157 0 my ( $self, $area, $name ) = @_;
2158 0 return _require_capability( $area, $name );
2159 },
2160 5 ),
2161 },
2162 );
2163 my $random_class = native_class(
2164 name => 'SecureRandom',
2165 static_methods => {
2166 bytes => native_function(
2167 name => 'bytes',
2168 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2169 0 my ( $self, $length ) = @_;
2170 0 $length = _non_negative_integer(
2171 $length,
2172 'SecureRandom.bytes',
2173 );
2174 0 return _random_bytes($length);
2175 },
2176 ),
2177 token => native_function(
2178 name => 'token',
2179 0 ▶ native => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
2180 0 my ( $self, $length ) = @_;
2181 0 ▶ $length = 32 if not defined $length;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $length 0 0 0
2182 0 $length = _non_negative_integer(
2183 $length,
2184 'SecureRandom.token',
2185 );
2186 0 return _base64url( urandom($length) );
2187 },
2188 ),
2189 int => native_function(
2190 name => 'int',
2191 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2192 0 my ( $self, $max ) = @_;
2193 0 $max = _positive_integer(
2194 $max,
2195 'SecureRandom.int',
2196 );
2197 0 return _random_int($max);
2198 },
2199 5 ),
2200 },
2201 );
2202 my $password_hash_class = native_class(
2203 name => 'PasswordHash',
2204 static_methods => {
2205 default_algorithm => native_function(
2206 name => 'default_algorithm',
2207 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2208 0 return $DEFAULT_PASSWORD_HASH_ALGORITHM;
2209 },
2210 ),
2211 hash => native_function(
2212 name => 'hash',
2213 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2214 0 my ( $self, $password, $options ) = @_;
2215 0 return _password_hash( $password, $options );
2216 },
2217 ),
2218 hash_async => native_function(
2219 name => 'hash_async',
2220 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2221 0 my ( $self, $password, $options ) = @_;
2222 0 my $value = _password_hash( $password, $options );
2223 0 return $runtime->_new_task(
2224 name => 'PasswordHash.hash_async',
2225 status => 'fulfilled',
2226 result => $value,
2227 );
2228 },
2229 ),
2230 verify => native_function(
2231 name => 'verify',
2232 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2233 0 my ( $self, $password, $encoded ) = @_;
2234 0 return _password_hash_verify( $password, $encoded );
2235 },
2236 ),
2237 verify_async => native_function(
2238 name => 'verify_async',
2239 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2240 0 my ( $self, $password, $encoded ) = @_;
2241 0 my $value = _password_hash_verify(
2242 $password,
2243 $encoded,
2244 );
2245 0 return $runtime->_new_task(
2246 name => 'PasswordHash.verify_async',
2247 status => 'fulfilled',
2248 result => $value,
2249 );
2250 },
2251 ),
2252 needs_rehash => native_function(
2253 name => 'needs_rehash',
2254 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2255 0 my ( $self, $encoded, $options ) = @_;
2256 0 return _password_hash_needs_rehash(
2257 $encoded,
2258 $options,
2259 );
2260 },
2261 ),
2262 derive_key => native_function(
2263 name => 'derive_key',
2264 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2265 0 my ( $self, $password, $options ) = @_;
2266 0 return _password_hash_derive_key(
2267 $password,
2268 $options,
2269 );
2270 },
2271 ),
2272 derive_key_async => native_function(
2273 name => 'derive_key_async',
2274 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2275 0 my ( $self, $password, $options ) = @_;
2276 0 my $value = _password_hash_derive_key(
2277 $password,
2278 $options,
2279 );
2280 0 return $runtime->_new_task(
2281 name => 'PasswordHash.derive_key_async',
2282 status => 'fulfilled',
2283 result => $value,
2284 );
2285 },
2286 5 ),
2287 },
2288 );
2289 my $kdf_class = native_class(
2290 name => 'KeyDerivation',
2291 static_methods => {
2292 hkdf_sha256 => native_function(
2293 name => 'hkdf_sha256',
2294 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2295 0 my ( $self, $ikm, $length, $salt, $info ) = @_;
2296 0 return _hkdf_sha256( $ikm, $length, $salt, $info );
2297 },
2298 ),
2299 hkdf_sha256_async => native_function(
2300 name => 'hkdf_sha256_async',
2301 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2302 0 my ( $self, $ikm, $length, $salt, $info ) = @_;
2303 0 my $value = _hkdf_sha256(
2304 $ikm,
2305 $length,
2306 $salt,
2307 $info,
2308 );
2309 0 return $runtime->_new_task(
2310 name => 'KeyDerivation.hkdf_sha256_async',
2311 status => 'fulfilled',
2312 result => $value,
2313 );
2314 },
2315 5 ),
2316 },
2317 );
2318 my $cipher_class = native_class(
2319 name => 'Cipher',
2320 static_methods => {
2321 generate_key => native_function(
2322 name => 'generate_key',
2323 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2324 0 my ( $self, $algorithm ) = @_;
2325 0 return _cipher_generate_key($algorithm);
2326 },
2327 ),
2328 encrypt => native_function(
2329 name => 'encrypt',
2330 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2331 0 my ( $self, $plaintext, $key, $options ) = @_;
2332 0 return _cipher_encrypt( $plaintext, $key, $options );
2333 },
2334 ),
2335 decrypt => native_function(
2336 name => 'decrypt',
2337 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2338 0 my ( $self, $envelope, $key, $options ) = @_;
2339 0 return _cipher_decrypt( $envelope, $key, $options );
2340 },
2341 ),
2342 encrypt_async => native_function(
2343 name => 'encrypt_async',
2344 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2345 0 my ( $self, $plaintext, $key, $options ) = @_;
2346 0 my $value = _cipher_encrypt(
2347 $plaintext,
2348 $key,
2349 $options,
2350 );
2351 0 return $runtime->_new_task(
2352 name => 'Cipher.encrypt_async',
2353 status => 'fulfilled',
2354 result => $value,
2355 );
2356 },
2357 ),
2358 decrypt_async => native_function(
2359 name => 'decrypt_async',
2360 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2361 0 my ( $self, $envelope, $key, $options ) = @_;
2362 0 my $value = _cipher_decrypt(
2363 $envelope,
2364 $key,
2365 $options,
2366 );
2367 0 return $runtime->_new_task(
2368 name => 'Cipher.decrypt_async',
2369 status => 'fulfilled',
2370 result => $value,
2371 );
2372 },
2373 5 ),
2374 },
2375 );
2376 my $public_key_class = native_class(
2377 name => 'PublicKey',
2378 methods => {
2379 verify => native_function(
2380 name => 'verify',
2381 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2382 0 my ( $self, $message, $signature ) = @_;
2383 0 return _public_key_verify(
2384 $self,
2385 $message,
2386 $signature,
2387 );
2388 },
2389 ),
2390 verify_async => native_function(
2391 name => 'verify_async',
2392 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2393 0 my ( $self, $message, $signature ) = @_;
2394 0 my $value = _public_key_verify(
2395 $self,
2396 $message,
2397 $signature,
2398 );
2399 0 return $runtime->_new_task(
2400 name => 'PublicKey.verify_async',
2401 status => 'fulfilled',
2402 result => $value,
2403 );
2404 },
2405 ),
2406 export => native_function(
2407 name => 'export',
2408 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2409 0 my ( $self, $options ) = @_;
2410 0 return _public_key_export( $self, $options );
2411 },
2412 5 ),
2413 },
2414 );
2415 my $time_class = native_class(
2416 name => 'Time',
2417 methods => {
2418 epoch => native_function(
2419 name => 'epoch',
2420 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2421 0 my ( $self ) = @_;
2422 0 return $self->slots->{_epoch};
2423 },
2424 5 ),
2425 },
2426 );
2427 5 my $certificate_class;
2428 $certificate_class = native_class(
2429 name => 'Certificate',
2430 static_methods => {
2431 parse => native_function(
2432 name => 'parse',
2433 1 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2434 1 my ( $self, $input ) = @_;
2435 1 return _certificate_parse(
2436 $certificate_class,
2437 $input,
2438 );
2439 },
2440 ),
2441 parse_chain => native_function(
2442 name => 'parse_chain',
2443 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2444 0 my ( $self, $input ) = @_;
2445 0 return _certificate_parse_chain(
2446 $certificate_class,
2447 $input,
2448 );
2449 },
2450 ),
2451 verify_chain => native_function(
2452 name => 'verify_chain',
2453 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2454 0 my ( $self, $chain, $options ) = @_;
2455 0 return _certificate_verify_chain(
2456 $chain,
2457 $options,
2458 );
2459 },
2460 ),
2461 },
2462 methods => {
2463 subject => native_function(
2464 name => 'subject',
2465 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2466 0 my ( $self ) = @_;
2467 0 my ( undef, $x509 ) = _certificate_state(
2468 $self,
2469 'Certificate.subject',
2470 );
2471 0 return $x509->subject;
2472 },
2473 ),
2474 issuer => native_function(
2475 name => 'issuer',
2476 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2477 0 my ( $self ) = @_;
2478 0 my ( undef, $x509 ) = _certificate_state(
2479 $self,
2480 'Certificate.issuer',
2481 );
2482 0 return $x509->issuer;
2483 },
2484 ),
2485 serial_number => native_function(
2486 name => 'serial_number',
2487 0 ▶ native => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
2488 0 my ( $self ) = @_;
2489 0 my ( undef, $x509 ) = _certificate_state(
2490 $self,
2491 'Certificate.serial_number',
2492 );
2493 0 ▶ my $serial = uc( $x509->serial // '' );
Condition0%0/2
$x509->serial // ""
l!l
00
MC/DC0%0/1
$x509->serial // ""
$x509->serial
Truth table0%0/2
A
A= $x509->serial
Aresult
11
00
2494 0 $serial =~ s/[^0-9A-F]//g;
2495 0 ▶ return $serial eq '' ? '00' : $serial;
Branch: 1 branch
BranchTrueFalseTotal
$serial eq '' ? : 0 0 0
2496 },
2497 ),
2498 not_before => native_function(
2499 name => 'not_before',
2500 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2501 0 my ( $self ) = @_;
2502 0 my ( undef, $x509 ) = _certificate_state(
2503 $self,
2504 'Certificate.not_before',
2505 );
2506 0 return _certificate_time(
2507 $time_class,
2508 $self,
2509 'not_before',
2510 $x509->notBefore,
2511 );
2512 },
2513 ),
2514 not_after => native_function(
2515 name => 'not_after',
2516 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2517 0 my ( $self ) = @_;
2518 0 my ( undef, $x509 ) = _certificate_state(
2519 $self,
2520 'Certificate.not_after',
2521 );
2522 0 return _certificate_time(
2523 $time_class,
2524 $self,
2525 'not_after',
2526 $x509->notAfter,
2527 );
2528 },
2529 ),
2530 fingerprint => native_function(
2531 name => 'fingerprint',
2532 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2533 0 my ( $self, $algorithm ) = @_;
2534 0 return _certificate_fingerprint(
2535 $self,
2536 $algorithm,
2537 );
2538 },
2539 ),
2540 to_der => native_function(
2541 name => 'to_der',
2542 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2543 0 my ( $self ) = @_;
2544 0 my ( $der ) = _certificate_state(
2545 $self,
2546 'Certificate.to_der',
2547 );
2548 0 return Zuzu::Value::BinaryString->new(
2549 bytes => $der,
2550 );
2551 },
2552 ),
2553 to_pem => native_function(
2554 name => 'to_pem',
2555 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2556 0 my ( $self ) = @_;
2557 0 my ( $der ) = _certificate_state(
2558 $self,
2559 'Certificate.to_pem',
2560 );
2561 0 return _der_to_pem_certificate($der);
2562 },
2563 ),
2564 public_key => native_function(
2565 name => 'public_key',
2566 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2567 0 my ( $self ) = @_;
2568 0 return _certificate_public_key(
2569 $public_key_class,
2570 $self,
2571 );
2572 },
2573 5 ),
2574 },
2575 );
2576 5 my $key_agreement_class;
2577 $key_agreement_class = native_class(
2578 name => 'KeyAgreement',
2579 static_methods => {
2580 generate => native_function(
2581 name => 'generate',
2582 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2583 0 my ( $self, $algorithm ) = @_;
2584 0 return _key_agreement_generate(
2585 $key_agreement_class,
2586 $algorithm,
2587 );
2588 },
2589 ),
2590 generate_async => native_function(
2591 name => 'generate_async',
2592 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2593 0 my ( $self, $algorithm ) = @_;
2594 0 my $value = _key_agreement_generate(
2595 $key_agreement_class,
2596 $algorithm,
2597 );
2598 0 return $runtime->_new_task(
2599 name => 'KeyAgreement.generate_async',
2600 status => 'fulfilled',
2601 result => $value,
2602 );
2603 },
2604 ),
2605 import_private => native_function(
2606 name => 'import_private',
2607 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2608 0 my ( $self, $key, $options ) = @_;
2609 0 return _key_agreement_import_private(
2610 $key_agreement_class,
2611 $key,
2612 $options,
2613 );
2614 },
2615 ),
2616 import_private_async => native_function(
2617 name => 'import_private_async',
2618 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2619 0 my ( $self, $key, $options ) = @_;
2620 0 my $value = _key_agreement_import_private(
2621 $key_agreement_class,
2622 $key,
2623 $options,
2624 );
2625 0 return $runtime->_new_task(
2626 name => 'KeyAgreement.import_private_async',
2627 status => 'fulfilled',
2628 result => $value,
2629 );
2630 },
2631 ),
2632 import_public => native_function(
2633 name => 'import_public',
2634 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2635 0 my ( $self, $key, $options ) = @_;
2636 0 return _key_agreement_import_public(
2637 $public_key_class,
2638 $key,
2639 $options,
2640 );
2641 },
2642 ),
2643 import_public_async => native_function(
2644 name => 'import_public_async',
2645 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2646 0 my ( $self, $key, $options ) = @_;
2647 0 my $value = _key_agreement_import_public(
2648 $public_key_class,
2649 $key,
2650 $options,
2651 );
2652 0 return $runtime->_new_task(
2653 name => 'KeyAgreement.import_public_async',
2654 status => 'fulfilled',
2655 result => $value,
2656 );
2657 },
2658 ),
2659 },
2660 methods => {
2661 public_key => native_function(
2662 name => 'public_key',
2663 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2664 0 my ( $self ) = @_;
2665 0 return _key_agreement_public_key(
2666 $public_key_class,
2667 $self,
2668 );
2669 },
2670 ),
2671 derive => native_function(
2672 name => 'derive',
2673 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2674 0 my ( $self, $peer ) = @_;
2675 0 return _key_agreement_derive( $self, $peer );
2676 },
2677 ),
2678 derive_async => native_function(
2679 name => 'derive_async',
2680 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2681 0 my ( $self, $peer ) = @_;
2682 0 my $value = _key_agreement_derive( $self, $peer );
2683 0 return $runtime->_new_task(
2684 name => 'KeyAgreement.derive_async',
2685 status => 'fulfilled',
2686 result => $value,
2687 );
2688 },
2689 ),
2690 export_private => native_function(
2691 name => 'export_private',
2692 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2693 0 my ( $self, $options ) = @_;
2694 0 return _key_agreement_export_private(
2695 $self,
2696 $options,
2697 );
2698 },
2699 5 ),
2700 },
2701 );
2702 5 my $signing_key_class;
2703 $signing_key_class = native_class(
2704 name => 'SigningKey',
2705 static_methods => {
2706 generate => native_function(
2707 name => 'generate',
2708 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2709 0 my ( $self, $algorithm ) = @_;
2710 0 return _signing_generate(
2711 $signing_key_class,
2712 $algorithm,
2713 );
2714 },
2715 ),
2716 generate_async => native_function(
2717 name => 'generate_async',
2718 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2719 0 my ( $self, $algorithm ) = @_;
2720 0 my $value = _signing_generate(
2721 $signing_key_class,
2722 $algorithm,
2723 );
2724 0 return $runtime->_new_task(
2725 name => 'SigningKey.generate_async',
2726 status => 'fulfilled',
2727 result => $value,
2728 );
2729 },
2730 ),
2731 import_private => native_function(
2732 name => 'import_private',
2733 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2734 0 my ( $self, $key, $options ) = @_;
2735 0 return _signing_import_private(
2736 $signing_key_class,
2737 $key,
2738 $options,
2739 );
2740 },
2741 ),
2742 import_private_async => native_function(
2743 name => 'import_private_async',
2744 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2745 0 my ( $self, $key, $options ) = @_;
2746 0 my $value = _signing_import_private(
2747 $signing_key_class,
2748 $key,
2749 $options,
2750 );
2751 0 return $runtime->_new_task(
2752 name => 'SigningKey.import_private_async',
2753 status => 'fulfilled',
2754 result => $value,
2755 );
2756 },
2757 ),
2758 import_public => native_function(
2759 name => 'import_public',
2760 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2761 0 my ( $self, $key, $options ) = @_;
2762 0 return _signing_import_public(
2763 $public_key_class,
2764 $key,
2765 $options,
2766 );
2767 },
2768 ),
2769 import_public_async => native_function(
2770 name => 'import_public_async',
2771 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2772 0 my ( $self, $key, $options ) = @_;
2773 0 my $value = _signing_import_public(
2774 $public_key_class,
2775 $key,
2776 $options,
2777 );
2778 0 return $runtime->_new_task(
2779 name => 'SigningKey.import_public_async',
2780 status => 'fulfilled',
2781 result => $value,
2782 );
2783 },
2784 ),
2785 },
2786 methods => {
2787 public_key => native_function(
2788 name => 'public_key',
2789 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2790 0 my ( $self ) = @_;
2791 0 return _signing_public_key(
2792 $public_key_class,
2793 $self,
2794 );
2795 },
2796 ),
2797 sign => native_function(
2798 name => 'sign',
2799 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2800 0 my ( $self, $message ) = @_;
2801 0 return _signing_sign( $self, $message );
2802 },
2803 ),
2804 sign_async => native_function(
2805 name => 'sign_async',
2806 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2807 0 my ( $self, $message ) = @_;
2808 0 my $value = _signing_sign( $self, $message );
2809 0 return $runtime->_new_task(
2810 name => 'SigningKey.sign_async',
2811 status => 'fulfilled',
2812 result => $value,
2813 );
2814 },
2815 ),
2816 export_private => native_function(
2817 name => 'export_private',
2818 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2819 0 my ( $self, $options ) = @_;
2820 0 return _signing_export_private(
2821 $self,
2822 $options,
2823 );
2824 },
2825 5 ),
2826 },
2827 );
2828 5 my $tls_identity_class;
2829 $tls_identity_class = native_class(
2830 name => 'TlsIdentity',
2831 static_methods => {
2832 from_pem => native_function(
2833 name => 'from_pem',
2834 1 ▶ native => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
2835 my (
2836 1 $self,
2837 $certificate_pem,
2838 $private_key_pem,
2839 $password,
2840 ) = @_;
2841 1 return _tls_identity_from_pem(
2842 $tls_identity_class,
2843 $certificate_pem,
2844 $private_key_pem,
2845 $password,
2846 );
2847 },
2848 ),
2849 from_pkcs12 => native_function(
2850 name => 'from_pkcs12',
2851 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2852 0 my ( $self, $bytes, $password ) = @_;
2853 0 return _tls_identity_from_pkcs12(
2854 $tls_identity_class,
2855 $bytes,
2856 $password,
2857 );
2858 },
2859 ),
2860 },
2861 methods => {
2862 certificate => native_function(
2863 name => 'certificate',
2864 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2865 0 my ( $self ) = @_;
2866 0 return _tls_identity_certificate(
2867 $certificate_class,
2868 $self,
2869 );
2870 },
2871 ),
2872 private_key => native_function(
2873 name => 'private_key',
2874 0 ▶ native => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2875 0 my ( $self ) = @_;
2876 0 return _tls_identity_private_key(
2877 $signing_key_class,
2878 $self,
2879 );
2880 },
2881 5 ),
2882 },
2883 );
2884  
2885 return {
2886 5 Secure => $secure_class,
2887 SecureRandom => $random_class,
2888 PasswordHash => $password_hash_class,
2889 KeyDerivation => $kdf_class,
2890 Cipher => $cipher_class,
2891 KeyAgreement => $key_agreement_class,
2892 SigningKey => $signing_key_class,
2893 Certificate => $certificate_class,
2894 PrivateKey => native_class( name => 'PrivateKey' ),
2895 PublicKey => $public_key_class,
2896 SealedBox => native_class( name => 'SealedBox' ),
2897 TlsIdentity => $tls_identity_class,
2898 };
2899 }
2900  
2901 3 1;
2902  
2903 =pod
2904  
2905 =head1 NAME
2906  
2907 Zuzu::Module::Secure - std/secure bindings for ZuzuScript.
2908  
2909 =head1 DESCRIPTION
2910  
2911 Implements the Phase 1 C<std/secure> runtime-supported module skeleton.
2912  
2913 =head1 COPYRIGHT AND LICENCE
2914  
2915 B<< Zuzu::Module::Secure >> is copyright Toby Inkster.
2916  
2917 It is free software; you may redistribute it and/or modify it under
2918 the terms of either the Artistic License 1.0 or the GNU General Public
2919 License version 2.
2920  
2921 =cut
« blib/script/zuzu-highlight.pl ↑ Summary blib/lib/Zuzu/Runtime.pm »