sub
new {
my
(
$class
,
%opts
) =
@_
;
die
'requires “content”!'
if
!
$opts
{
'content'
};
die
'requires “type”!'
if
!
$opts
{
'type'
};
die
'requires “issuer_cert_uri”!'
if
!
$opts
{
'issuer_cert_uri'
};
my
$self
=
bless
{},
$class
;
$self
->{
"_$_"
} =
$opts
{
$_
}
for
qw(content type issuer_cert_uri)
;
return
$self
;
}
sub
issuers_pem {
my
(
$self
) =
@_
;
Call::Context::must_be_list();
my
@pems
;
my
$uri
=
$self
->{
'_issuer_cert_uri'
};
while
(
$uri
) {
my
$http
= Net::ACME::HTTP->new();
my
$resp
=
$http
->get(
$uri
);
_STATIC_die_if_wrong_mime_type(
$resp
->header(
'content-type'
) );
push
@pems
, _STATIC_der_to_pem(
$resp
->content() );
my
$new_uri
= {
$resp
->links() }->{
'up'
};
undef
$new_uri
if
$new_uri
&&
$new_uri
eq
$uri
;
$uri
=
$new_uri
;
}
return
@pems
;
}
sub
pem {
my
(
$self
) =
@_
;
if
(
defined
$self
->{
'_type'
} ) {
_STATIC_die_if_wrong_mime_type(
$self
->{
'_type'
} );
return
_STATIC_der_to_pem(
$self
->{
'_content'
} );
}
return
undef
;
}
sub
_STATIC_die_if_wrong_mime_type {
my
(
$type
) =
@_
;
if
(
$type
ne
'application/pkix-cert'
) {
die
"Unrecognized certificate MIME type: “$type”"
;
}
return
;
}
sub
_STATIC_der_to_pem {
my
(
$der
) =
@_
;
return
Crypt::Format::der2pem(
$der
,
'CERTIFICATE'
);
}
1;