File Coverage

blib/lib/Crypt/Mac/BLAKE2s.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::BLAKE2s;
2              
3             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
4              
5 2     2   81856 use strict;
  2         4  
  2         56  
6 2     2   10 use warnings;
  2         4  
  2         102  
7             our $VERSION = '0.089';
8              
9 2     2   6 use base qw(Crypt::Mac Exporter);
  2         4  
  2         653  
10             our %EXPORT_TAGS = ( all => [qw( blake2s blake2s_hex blake2s_b64 blake2s_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::BLAKE2s - Message authentication code BLAKE2s MAC (RFC 7693)
21              
22             =head1 SYNOPSIS
23              
24             ### Functional interface:
25             use Crypt::Mac::BLAKE2s qw( blake2s blake2s_hex blake2s_b64 blake2s_b64u );
26              
27             # calculate MAC from string/buffer
28             my $blake2s_raw = blake2s($size, $key, 'data buffer');
29             my $blake2s_hex = blake2s_hex($size, $key, 'data buffer');
30             my $blake2s_b64 = blake2s_b64($size, $key, 'data buffer');
31             my $blake2s_b64u = blake2s_b64u($size, $key, 'data buffer');
32              
33             ### OO interface:
34             use Crypt::Mac::BLAKE2s;
35              
36             my $d = Crypt::Mac::BLAKE2s->new($size, $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::BLAKE2s->new($size, $key)->add('any data')->b64umac;
42              
43             # or MAC a file instead
44             my $file_result_raw = Crypt::Mac::BLAKE2s->new($size, $key)->addfile('filename.dat')->mac;
45              
46             =head1 DESCRIPTION
47              
48             Provides an interface to the BLAKE2s 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::BLAKE2s qw( blake2s blake2s_hex blake2s_b64 blake2s_b64u );
57              
58             Or all of them at once:
59              
60             use Crypt::Mac::BLAKE2s ':all';
61              
62             =head1 FUNCTIONS
63              
64             =head2 blake2s
65              
66             Joins all arguments into a single string and returns its BLAKE2s 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 $blake2s_raw = blake2s($size, $key, 'data buffer');
76             #or
77             my $blake2s_raw = blake2s($size, $key, 'any data', 'more data', 'even more data');
78              
79             =head2 blake2s_hex
80              
81             Joins all arguments into a single string and returns its BLAKE2s message authentication code encoded as a hexadecimal string.
82              
83             my $blake2s_hex = blake2s_hex($size, $key, 'data buffer');
84             #or
85             my $blake2s_hex = blake2s_hex($size, $key, 'any data', 'more data', 'even more data');
86              
87             =head2 blake2s_b64
88              
89             Joins all arguments into a single string and returns its BLAKE2s message authentication code encoded as a Base64 string.
90              
91             my $blake2s_b64 = blake2s_b64($size, $key, 'data buffer');
92             #or
93             my $blake2s_b64 = blake2s_b64($size, $key, 'any data', 'more data', 'even more data');
94              
95             =head2 blake2s_b64u
96              
97             Joins all arguments into a single string and returns its BLAKE2s message authentication code encoded as a Base64 URL-safe string (see RFC 4648 section 5).
98              
99             my $blake2s_b64url = blake2s_b64u($size, $key, 'data buffer');
100             #or
101             my $blake2s_b64url = blake2s_b64u($size, $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::BLAKE2s->new($size, $key);
109              
110             =head2 new
111              
112             my $d = Crypt::Mac::BLAKE2s->new($size, $key);
113              
114             # $size .. [integer] desired MAC output size in bytes (1 - 32)
115             # $key ... [binary string] the key (1 - 32 bytes)
116              
117             =head2 clone
118              
119             $d->clone();
120              
121             =head2 add
122              
123             Appends data to the message. Returns the object itself (for chaining).
124             Croaks if the object has already been finalized by C, C,
125             C, or C.
126              
127             Each argument is converted to bytes using Perl's usual scalar stringification.
128             Defined scalars, including numbers and string-overloaded objects, are
129             accepted. C is treated as an empty string and may emit Perl's usual
130             "uninitialized value" warning.
131              
132             $d->add('any data');
133             #or
134             $d->add('any data', 'more data', 'even more data');
135              
136             =head2 addfile
137              
138             Reads the file content and appends it to the message. Returns the object itself
139             (for chaining). Croaks if the object has already been finalized by C,
140             C, C, or C.
141              
142             $d->addfile('filename.dat');
143             #or
144             my $filehandle = ...; # existing binary-mode filehandle
145             $d->addfile($filehandle);
146              
147             =head2 mac
148              
149             Returns the binary MAC (raw bytes) and finalizes the object. After the first
150             call to C, C, C, or C, later calls to C,
151             C, or any MAC getter croak.
152              
153             my $result_raw = $d->mac();
154              
155             =head2 hexmac
156              
157             Returns the MAC encoded as a lowercase hexadecimal string and finalizes the
158             object. After the first call to C, C, C, or C,
159             later calls to C, C, or any MAC getter croak.
160              
161             my $result_hex = $d->hexmac();
162              
163             =head2 b64mac
164              
165             Returns the MAC encoded as a Base64 string with trailing C<=> padding and
166             finalizes the object. After the first call to C, C, C, or
167             C, later calls to C, C, or any MAC getter croak.
168              
169             my $result_b64 = $d->b64mac();
170              
171             =head2 b64umac
172              
173             Returns the MAC encoded as a Base64 URL-safe string (no trailing C<=>) and
174             finalizes the object. After the first call to C, C, C, or
175             C, later calls to C, C, or any MAC getter croak.
176              
177             my $result_b64url = $d->b64umac();
178              
179             =head1 SEE ALSO
180              
181             =over
182              
183             =item * L
184              
185             =item * L
186              
187             =back
188              
189             =cut