File Coverage

blib/lib/Crypt/Bear/X509/Certificate/Chain.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 32 34 94.1


line stmt bran cond sub pod time code
1             package Crypt::Bear::X509::Certificate::Chain;
2             $Crypt::Bear::X509::Certificate::Chain::VERSION = '0.004';
3 3     3   151600 use strict;
  3         6  
  3         87  
4 3     3   8 use warnings;
  3         5  
  3         142  
5              
6 3     3   323 use Crypt::Bear;
  3         5  
  3         73  
7 3     3   714 use Crypt::Bear::PEM;
  3         6  
  3         654  
8              
9             sub load {
10 1     1 1 4 my ($class, $filename) = @_;
11              
12 1         7 my $self = $class->new;
13              
14 1 50       48 open my $fh, '<:crlf', $filename or die "Could not open certificate $filename: $!";
15 1         2 my $raw = do { local $/; <$fh> };
  1         5  
  1         19  
16 1         809 my (@items) = Crypt::Bear::PEM::pem_decode($raw);
17              
18 1         6 while (my ($banner, $content) = splice @items, 0, 2) {
19 1 50       5 die "File $filename does not contain a certificate" unless $banner =~ /CERTIFICATE/;
20 1         335 my $cert = Crypt::Bear::X509::Certificate->new($content);
21 1         21 $self->add($cert);
22             }
23              
24 1         23 return $self;
25             }
26              
27             1;
28              
29             #ABSTRACT: A certificate chain for BearSSL
30              
31             __END__