blib/lib/Web/ID/Certificate.pm

filter: Statementstmt 100% 78 / 78 Branchbran 83.3% 5 / 6 Conditioncond 60.0% 3 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 25 / 25 Podpod 100% 1 / 1 totaltotal 94.9% 112 / 118 CC 6 SCAR 4.3
CC
6
Cov
97%
timely
4.0
_sort_san
2.1
__ANON__
2.0
CRAP 1.5
« blib/lib/Web/ID/RSAKey.pm ↑ Summary blib/lib/Web/ID/SAN/URI.pm »
1 package Web::ID::Certificate;
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 $Web::ID::Certificate::AUTHORITY = 'cpan:TOBYINK';
8 3 $Web::ID::Certificate::VERSION = '1.927';
9 }
10  
11 3 ▶use Crypt::X509 0.50 (); # why the hell does this export anything?!
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use DateTime 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use MIME::Base64 0 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Web::ID::Types -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Web::ID::SAN;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Web::ID::SAN::Email;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Web::ID::SAN::URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Web::ID::Util qw(:default part);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # Partly sorts a list of Web::ID::SAN objects,
22 # prioritising URIs and Email addresses.
23 #
24 sub _sort_san
25 8 ▶{
Subroutine _sort_san: called CC=2 SCAR=7.2
26 9 ▶ map { ref($_) eq 'ARRAY' ? (@$_) : () }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 9 0 9
27 part {
28 if ($_->isa("Web::ID::SAN::URI")) { 0 }
29 elsif ($_->isa("Web::ID::SAN::Email")) { 1 }
30 else { 2 }
31 }
32 8 @_;
33 }
34  
35 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use namespace::sweep -also => '_sort_san';
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 3 has pem => (
39 is => read_only,
40 isa => Str,
41 required => true,
42 coerce => false,
43 );
44  
45 3 has _der => (
46 is => read_only,
47 isa => Str,
48 required => true,
49 lazy_build => true,
50 );
51  
52 3 has _x509 => (
53 is => read_only,
54 isa => Type::Utils::class_type({ class => "Crypt::X509" }),
55 lazy_build => true,
56 );
57  
58 3 has public_key => (
59 is => read_only,
60 isa => Rsakey,
61 lazy_build => true,
62 handles => [qw(modulus exponent)],
63 );
64  
65 3 has subject_alt_names => (
66 is => read_only,
67 isa => ArrayRef,
68 lazy_build => true,
69 );
70  
71 has $_ => (
72 is => read_only,
73 isa => DateTime,
74 lazy_build => true,
75 coerce => true,
76 3 ) for qw( not_before not_after );
77  
78 3 has san_factory => (
79 is => read_only,
80 isa => CodeRef,
81 lazy_build => true,
82 );
83  
84 3 has fingerprint => (
85 is => read_only,
86 isa => Str,
87 lazy_build => true,
88 );
89  
90 sub _build_fingerprint
91 1 ▶{
Subroutine _build_fingerprint: called CC=1 SCAR=0.0
92 1 lc sha1_hex( shift->_der );
93 }
94  
95 sub _build__der
96 13 ▶{
Subroutine _build__der: called CC=1 SCAR=0.0
97 13 my @lines = split /\n/, shift->pem;
98 13 decode_base64(join "\n", grep { !/--(BEGIN|END) CERTIFICATE--/ } @lines);
99 }
100  
101 sub _build__x509
102 13 ▶{
Subroutine _build__x509: called CC=1 SCAR=0.0
103 13 return "Crypt::X509"->new(cert => shift->_der);
104 }
105  
106 sub _build_public_key
107 11 ▶{
Subroutine _build_public_key: called CC=1 SCAR=0.0
108 11 my ($self) = @_;
109 11 Rsakey->new($self->_x509->pubkey_components);
110 }
111  
112 sub _build_subject_alt_names
113 8 ▶{
Subroutine _build_subject_alt_names: called CC=1 SCAR=0.0
114 8 my ($self) = @_;
115 8 my $factory = $self->san_factory;
116  
117 [_sort_san(
118 map {
119 10 my ($type, $value) = split /=/, $_, 2;
120 10 $factory->(type => $type, value => $value);
121 }
122 8 @{ $self->_x509->SubjectAltName }
123 )];
124 }
125  
126 sub _build_not_before
127 8 ▶{
Subroutine _build_not_before: called CC=1 SCAR=0.0
128 8 my ($self) = @_;
129 8 return $self->_x509->not_before;
130 }
131  
132 sub _build_not_after
133 8 ▶{
Subroutine _build_not_after: called CC=1 SCAR=0.0
134 8 my ($self) = @_;
135 8 return $self->_x509->not_after;
136 }
137  
138 my $default_san_factory = sub
139 10 ▶{
Subroutine __ANON__: called CC=2 SCAR=7.1
140 10 my (%args) = @_;
141 my $class = {
142 uniformResourceIdentifier => 'Web::ID::SAN::URI',
143 rfc822Name => 'Web::ID::SAN::Email',
144 }->{ $args{type} }
145 10 ▶ // "Web::ID::SAN";
Condition50%1/2
{"uniformResourceIdentifier", "Web::ID::SAN::URI", "rfc822Name", "Web::ID::SAN::Email"}->{$args{"type"}} // "Web::ID::SAN"
l!l
100
MC/DC0%0/1
{"uniformResourceIdentifier", "Web::ID::SAN::URI", "rfc822Name", "Web::ID::SAN::Email"}->{$args{"type"}} // "Web::ID::SAN"
{"uniformResourceIdentifier", "Web::ID::SAN::URI", "rfc822Name", "Web::ID::SAN::Email"}->{$args{"type"}}
Truth table50%1/2
A
A= {"uniformResourceIdentifier", "Web::ID::SAN::URI", "rfc822Name", "Web::ID::SAN::Email"}->{$args{"type"}}
Aresult
11
00
146 10 $class->new(%args);
147 3 };
148  
149 sub _build_san_factory
150 8 ▶{
Subroutine _build_san_factory: called CC=1 SCAR=0.0
151 8 return $default_san_factory;
152 }
153  
154 sub timely
155 12 ▶{
Subroutine timely: called CC=4 SCAR=13.9
Pod documented
156 12 my ($self, $now) = @_;
157 12 ▶ $now //= DateTime->coerce('now');
Condition66%2/3
$now //= &DateTime()->coerce("now")
l!l&&r!l&&!r
570
MC/DC0%0/2
$now //= &DateTime()->coerce("now")
$now &DateTime()->coerce("now")
Truth table66%2/3
A //= B
A= $nowB= &DateTime()->coerce("now")
ABresult
1X1
011
000
158
159 12 ▶ return if $now > $self->not_after;
Branch: 1 branch
BranchTrueFalseTotal
if $now > $self->not_after 1 11 12
160 11 ▶ return if $now < $self->not_before;
Branch: 1 branch
BranchTrueFalseTotal
if $now < $self->not_before 1 10 11
161
162 10 return $self;
163 }
164  
165 3 __PACKAGE__
166 __END__
« blib/lib/Web/ID/RSAKey.pm ↑ Summary blib/lib/Web/ID/SAN/URI.pm »