File Coverage

blib/lib/GnuPG/Signature.pm
Criterion Covered Total %
statement 6 16 37.5
branch 0 8 0.0
path n/a
condition 0 3 0.0
subroutine 2 4 50.0
pod 2 2 100.0
total 10 33 30.3


line stmt bran path cond sub pod time code
1               # Signature.pm
2               # - providing an object-oriented approach to GnuPG key signatures
3               #
4               # Copyright (C) 2000 Frank J. Tobin <ftobin@cpan.org>
5               #
6               # This module is free software; you can redistribute it and/or modify it
7               # under the same terms as Perl itself.
8               #
9               # This program is distributed in the hope that it will be useful,
10               # but WITHOUT ANY WARRANTY; without even the implied warranty of
11               # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12               #
13               # $Id: Signature.pm,v 1.4 2001/08/21 13:31:50 ftobin Exp $
14               #
15                
16               package GnuPG::Signature;
17 5       5   51 use Moo;
  5           16  
  5           49  
18 5       5   1981 use MooX::late;
  5           14  
  5           36  
19                
20               has [qw(
21               validity
22               algo_num
23               hex_id
24               user_id_string
25               date
26               date_string
27               expiration_date
28               expiration_date_string
29               sig_class
30               is_exportable
31               )] => (
32               isa => 'Any',
33               is => 'rw',
34               );
35                
36               sub is_valid {
37 0       0 1   my $self = shift;
38 0             return $self->validity eq '!';
39               }
40                
41               sub compare {
42 0       0 1   my ($self, $other) = @_;
43                
44 0             my @compared_fields = qw(
45               validity
46               algo_num
47               hex_id
48               date
49               date_string
50               sig_class
51               is_exportable
52               );
53                
54 0             foreach my $field ( @compared_fields ) {
55 0 0           return 0 unless $self->$field eq $other->$field;
56               }
57               # check for expiration if present?
58 0 0           return 0 unless (defined $self->expiration_date) == (defined $other->expiration_date);
59 0 0           if (defined $self->expiration_date) {
60 0 0   0       return 0 unless (($self->expiration_date == $other->expiration_date) ||
61               ($self->expiration_date_string eq $other->expiration_date_string));
62               }
63 0             return 1;
64               }
65                
66               1;
67                
68               __END__
69                
70               =head1 NAME
71                
72               GnuPG::Signature - GnuPG Key Signature Objects
73                
74               =head1 SYNOPSIS
75                
76               # assumes a GnuPG::Key or GnuPG::UserID or GnuPG::UserAttribute object in $signed
77               my $signing_id = $signed->signatures->[0]->hex_id();
78                
79               =head1 DESCRIPTION
80                
81               GnuPG::Signature objects are generally not instantiated
82               on their own, but rather as part of GnuPG::Key objects.
83               They embody various aspects of a GnuPG signature on a key.
84                
85               =head1 OBJECT METHODS
86                
87               =over 4
88                
89               =item new( I<%initialization_args> )
90                
91               This methods creates a new object. The optional arguments are
92               initialization of data members.
93                
94               =item is_valid()
95                
96               Returns 1 if GnuPG was able to cryptographically verify the signature,
97               otherwise 0.
98                
99               =item compare( I<$other> )
100                
101               Returns non-zero only when this Signature is identical to the other
102               GnuPG::Signature.
103                
104               =back
105                
106               =head1 OBJECT DATA MEMBERS
107                
108               =over 4
109                
110               =item validity
111                
112               A character indicating the cryptographic validity of the key. GnuPG
113               uses at least the following characters: "!" means valid, "-" means not
114               valid, "?" means unknown (e.g. if the supposed signing key is not
115               present in the local keyring), and "%" means an error occurred (e.g. a
116               non-supported algorithm). See the documentation for --check-sigs in
117               gpg(1).
118                
119               =item algo_num
120                
121               The number of the algorithm used for the signature.
122                
123               =item hex_id
124                
125               The hex id of the signing key.
126                
127               =item user_id_string
128                
129               The first user id string on the key that made the signature.
130               This may not be defined if the signing key is not on the local keyring.
131                
132               =item sig_class
133                
134               Signature class. This is the numeric value of the class of signature.
135                
136               A table of possible classes of signatures and their numeric types can
137               be found at http://tools.ietf.org/html/rfc4880#section-5.2.1
138                
139               =item is_exportable
140                
141               returns 0 for local-only signatures, non-zero for exportable
142               signatures.
143                
144               =item date_string
145                
146               The formatted date the signature was performed on.
147                
148               =item date
149                
150               The date the signature was performed, represented as the number of
151               seconds since midnight 1970-01-01 UTC.
152                
153               =item expiration_date_string
154                
155               The formatted date the signature will expire (signatures without
156               expiration return undef).
157                
158               =item expiration_date
159                
160               The date the signature will expire, represented as the number of
161               seconds since midnight 1970-01-01 UTC (signatures without expiration
162               return undef)
163                
164               =back
165                
166               =head1 SEE ALSO
167                
168                
169               =cut