| 1 | package Net::ACME::Utils; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | Net::ACME::Utils - utilities for C<Net::ACME> | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Net::ACME::Utils::verify_token('blah/blah'); #dies | ||||||||||||||||||||||||||||
| 12 | Net::ACME::Utils::verify_token('blah-blah'); #succeeds | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | This module is a home for “miscellaneous” functions that just aren’t | ||||||||||||||||||||||||||||
| 17 | in other modules. Think carefully before expanding this module; it’s | ||||||||||||||||||||||||||||
| 18 | probably better, if possible, to put new functionality into more | ||||||||||||||||||||||||||||
| 19 | topic-specific modules rather than this “catch-all” one. | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use MIME::Base64 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 13 | *_to_base64url = \&MIME::Base64::encode_base64url; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 13 | ▶ | use Net::ACME::Crypt (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 13 | ▶ | use Net::ACME::X (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 13 | my %KEY_OBJ_CACHE; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | #Clear out the cache prior to global destruction. | ||||||||||||||||||||||||||||
| 35 | 13 | ▶ | END { | ||||||||||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 13 | %KEY_OBJ_CACHE = (); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 9 | ▶ | sub verify_token { | ||||||||||||||||||||||||||
|
Subroutine
verify_token: called CC=6 SCAR=18.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 9 | my ($token) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | #cf. eval_bug.readme | ||||||||||||||||||||||||||||
| 43 | 9 | my $eval_err = $@; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 9 | eval { | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 9 | ▶ | die Net::ACME::X::create('Empty') if !defined $token || !length $token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $token and length $token
MC/DC0%0/2
defined $token and length $token
defined $token
length $token
Truth table33%1/3
A and B
A= defined $tokenB= length $token
| |||||||||||||||||||||||||||||
| 48 | 9 | ▶ | die Net::ACME::X::create('Empty') if $token =~ m<\A\s*\z>; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 9 | ▶ | if ( $token =~ m<[^0-9a-zA-Z_-]> ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 1 | die Net::ACME::X::create( 'InvalidCharacters', "“$token” contains invalid Base64-URL characters.", { value => $token } ); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 9 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | my $message = $@->to_string(); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | die Net::ACME::X::create( 'InvalidParameter', "“$token” is not a valid ACME token. ($message)" ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 8 | $@ = $eval_err; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 8 | return; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | #Use this to avoid a Try::Tiny dependency. | ||||||||||||||||||||||||||||
| 68 | 8 | ▶ | sub thing_isa { | ||||||||||||||||||||||||||
|
Subroutine
thing_isa: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 8 | my ($thing, $class) = @_; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | #cf. eval_bug.readme | ||||||||||||||||||||||||||||
| 72 | 8 | my $eval_err = $@; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 8 | my $isa = eval { $thing->isa($class) }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 8 | $@ = $eval_err; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 8 | return $isa; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 13 | 1; | |||||||||||||||||||||||||||