File Coverage

blib/lib/Crypt/Mac/Poly1305.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Crypt::Mac::Poly1305;
2              
3             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
4              
5 2     2   79635 use strict;
  2         4  
  2         63  
6 2     2   11 use warnings;
  2         3  
  2         102  
7             our $VERSION = '0.089';
8              
9 2     2   8 use base qw(Crypt::Mac Exporter);
  2         3  
  2         563  
10             our %EXPORT_TAGS = ( all => [qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u )] );
11             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
12             our @EXPORT = qw();
13              
14             1;
15              
16             =pod
17              
18             =head1 NAME
19              
20             Crypt::Mac::Poly1305 - Message authentication code Poly1305 (RFC 7539)
21              
22             =head1 SYNOPSIS
23              
24             ### Functional interface:
25             use Crypt::Mac::Poly1305 qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u );
26              
27             # calculate MAC from string/buffer
28             my $poly1305_raw = poly1305($key, 'data buffer');
29             my $poly1305_hex = poly1305_hex($key, 'data buffer');
30             my $poly1305_b64 = poly1305_b64($key, 'data buffer');
31             my $poly1305_b64u = poly1305_b64u($key, 'data buffer');
32              
33             ### OO interface:
34             use Crypt::Mac::Poly1305;
35              
36             my $d = Crypt::Mac::Poly1305->new($key);
37             $d->add('any data');
38             my $result_hex = $d->hexmac; # finalizes the object
39              
40             # for another output encoding use a fresh object (or clone before finalizing)
41             my $result_b64u = Crypt::Mac::Poly1305->new($key)->add('any data')->b64umac;
42              
43             # or MAC a file instead
44             my $file_result_raw = Crypt::Mac::Poly1305->new($key)->addfile('filename.dat')->mac;
45              
46             =head1 DESCRIPTION
47              
48             Provides an interface to the Poly1305 message authentication code (MAC) algorithm.
49              
50             =head1 EXPORT
51              
52             Nothing is exported by default.
53              
54             You can export selected functions:
55              
56             use Crypt::Mac::Poly1305 qw( poly1305 poly1305_hex poly1305_b64 poly1305_b64u );
57              
58             Or all of them at once:
59              
60             use Crypt::Mac::Poly1305 ':all';
61              
62             =head1 FUNCTIONS
63              
64             =head2 poly1305
65              
66             Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a binary string.
67              
68             Data arguments for the functional helpers are converted to byte strings using
69             Perl's usual scalar stringification. Defined scalars, including numbers and
70             string-overloaded objects, are accepted. C is treated as an empty
71             string and may emit Perl's usual "uninitialized value" warning. The same
72             rules apply to C, C, and
73             C.
74              
75             my $poly1305_raw = poly1305($key, 'data buffer');
76             #or
77             my $poly1305_raw = poly1305($key, 'any data', 'more data', 'even more data');
78              
79             =head2 poly1305_hex
80              
81             Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a hexadecimal string.
82              
83             my $poly1305_hex = poly1305_hex($key, 'data buffer');
84             #or
85             my $poly1305_hex = poly1305_hex($key, 'any data', 'more data', 'even more data');
86              
87             =head2 poly1305_b64
88              
89             Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a Base64 string.
90              
91             my $poly1305_b64 = poly1305_b64($key, 'data buffer');
92             #or
93             my $poly1305_b64 = poly1305_b64($key, 'any data', 'more data', 'even more data');
94              
95             =head2 poly1305_b64u
96              
97             Joins all arguments into a single string and returns its Poly1305 message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5).
98              
99             my $poly1305_b64url = poly1305_b64u($key, 'data buffer');
100             #or
101             my $poly1305_b64url = poly1305_b64u($key, 'any data', 'more data', 'even more data');
102              
103             =head1 METHODS
104              
105             Unless noted otherwise, assume C<$d> is an existing MAC object created via
106             C, for example:
107              
108             my $d = Crypt::Mac::Poly1305->new($key);
109              
110             =head2 new
111              
112             my $d = Crypt::Mac::Poly1305->new($key);
113              
114             # $key .. [binary string] exactly 32 bytes (256 bits); a fresh one-time key per message
115              
116             =head2 clone
117              
118             $d->clone();
119              
120             =head2 add
121              
122             Appends data to the message. Returns the object itself (for chaining).
123             Croaks if the object has already been finalized by C, C,
124             C, or C.
125              
126             Each argument is converted to bytes using Perl's usual scalar stringification.
127             Defined scalars, including numbers and string-overloaded objects, are
128             accepted. C is treated as an empty string and may emit Perl's usual
129             "uninitialized value" warning.
130              
131             $d->add('any data');
132             #or
133             $d->add('any data', 'more data', 'even more data');
134              
135             =head2 addfile
136              
137             Reads the file content and appends it to the message. Returns the object itself
138             (for chaining). Croaks if the object has already been finalized by C,
139             C, C, or C.
140              
141             $d->addfile('filename.dat');
142             #or
143             my $filehandle = ...; # existing binary-mode filehandle
144             $d->addfile($filehandle);
145              
146             =head2 mac
147              
148             Returns the binary MAC (raw bytes) and finalizes the object. After the first
149             call to C, C, C, or C, later calls to C,
150             C, or any MAC getter croak.
151              
152             my $result_raw = $d->mac();
153              
154             =head2 hexmac
155              
156             Returns the MAC encoded as a lowercase hexadecimal string and finalizes the
157             object. After the first call to C, C, C, or C,
158             later calls to C, C, or any MAC getter croak.
159              
160             my $result_hex = $d->hexmac();
161              
162             =head2 b64mac
163              
164             Returns the MAC encoded as a Base64 string with trailing C<=> padding and
165             finalizes the object. After the first call to C, C, C, or
166             C, later calls to C, C, or any MAC getter croak.
167              
168             my $result_b64 = $d->b64mac();
169              
170             =head2 b64umac
171              
172             Returns the MAC encoded as a Base64 URL-safe string (no trailing C<=>) and
173             finalizes the object. After the first call to C, C, C, or
174             C, later calls to C, C, or any MAC getter croak.
175              
176             my $result_b64url = $d->b64umac();
177              
178             =head1 SEE ALSO
179              
180             =over
181              
182             =item * L
183              
184             =item * L
185              
186             =back
187              
188             =cut