Mojo/SAML/Document/KeyInfo.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 37 CC 4 SCAR 25.1
CC
4
Cov
0%
x509_string
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 package Mojo::SAML::Document::KeyInfo;
2  
3 use Mojo::Base 'Mojo::SAML::Document';
4  
5 use Mojo::Template;
6 use Mojo::XMLSig;
7  
8 my $isa = sub {
9 my ($obj, $class) = @_;
10 Scalar::Util::blessed($obj) && $obj->isa($class);
11 };
12  
13 has template => sub { shift->build_template(<<'XML') };
14 <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
15 % if (my $name = $self->name) {
16 <KeyName><%= $name %></KeyName>
17 % }
18 <X509Data>
19 <X509Certificate><%= $self->x509_string // '' %></X509Certificate>
20 </X509Data>
21 </KeyInfo>
22 XML
23  
24 has 'cert';
25 has 'name';
26  
27 sub x509_string {
28 my $self = shift;
29 return undef unless my $cert = $self->cert;
30  
31 my $text = $cert->$isa('Crypt::OpenSSL::X509') ? $cert->as_string : undef;
32  
33 Carp::croak 'Unknown cert object type'
34 unless defined $text;
35  
36 return Mojo::XMLSig::trim_cert($text);
37 }
38  
39 1;
40  
41 =head1 NAME
42  
43 Mojo::SAML::Document::KeyInfo
44  
45 =head1 DESCRIPTION
46  
47 Represents an KeyInfo XML-Sig tag
48  
49 =head1 ATTRIBUTES
50  
51 L<Mojo::SAML::Document::KeyInfo> inherits all attributes from L<Mojo::SAML::Document> and implements the following new ones.
52  
53 =head2 cert
54  
55 Optional.
56 If given, it must be an instance of L<Crypt::OpenSSL::X509>.
57 If not given, the tag is still generated, however, the content of the X509Certificate tag will be empty.
58 It may later be filled in via some signing process.
59  
60 =head2 name
61  
62 Optional.
63 The certificate name, used by some applications to distinguish between possible certificates.
64  
65 =head2 template
66  
67 A template specific to the document type.
68  
69 =head1 METHODS
70  
71 L<Mojo::SAML::Document::KeyInfo> inherits all methods from L<Mojo::SAML::Document> and implements the following new ones.
72  
73 =head2 x509_string
74  
75 If the L</cert> is given, this method formats and returns it for inserting into the X509Certificate tag body.
76