blib/lib/SPVM/Digest/SHA.pm

filter: Statementstmt 100% 2 / 2 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 2 / 2 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary
1 package SPVM::Digest::SHA;
2  
3 1 our $VERSION = "0.072";
4  
5 1 1;
6  
7 =head1 Name
8  
9 SPVM::Digest::SHA - SHA-1/224/256/384/512
10  
11 =head1 Description
12  
13 Digest::SHA in L<SPVM> calculates SHA-1/224/256/384/512.
14  
15 =head1 Usage
16  
17 use Digest::SHA;
18
19 my $digest = Digest::SHA->sha1($data);
20 my $digest = Digest::SHA->sha1_hex($data);
21 my $digest = Digest::SHA->sha1_base64($data);
22
23 my $digest = Digest::SHA->sha256($data);
24 my $digest = Digest::SHA->sha384_hex($data);
25 my $digest = Digest::SHA->sha512_base64($data);
26  
27 Object Oriented Programming:
28  
29 my $sha = Digest::SHA->new($alg);
30
31 $sha->add($data);
32
33 my $sha_copy = $sha->clone;
34
35 my $digest = $sha->digest;
36 my $digest = $sha->hexdigest;
37 my $digest = $sha->b64digest;
38  
39 =head1 Class Methods
40  
41 =head2 sha1
42  
43 C<static method sha1 : string ($data : string);>
44  
45 Receive the input date and return its SHA-1 digest encoded as a binary string.
46  
47 =head2 sha1_hex
48  
49 C<static method sha1_hex : string ($data : string);>
50  
51 Receive the input date and return its SHA-1 digest encoded as a hexadecimal string.
52  
53 =head2 sha1_base64
54  
55 C<static method sha1_base64 : string ($data : string);>
56  
57 Receive the input date and return its SHA-1 digest encoded as a Base64 string.
58  
59 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
60  
61 =head2 sha224
62  
63 C<static method sha224 : string ($data : string);>
64  
65 Receive the input date and return its SHA-224 digest encoded as a binary string.
66  
67 =head2 sha224_hex
68  
69 C<static method sha224_hex : string ($data : string);>
70  
71 Receive the input date and return its SHA-224 digest encoded as a hexadecimal string.
72  
73 =head2 sha224_base64
74  
75 C<static method sha224_base64 : string ($data : string);>
76  
77 Receive the input date and return its SHA-224 digest encoded as a Base64 string.
78  
79 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
80  
81 =head2 sha256
82  
83 C<static method sha256 : string ($data : string);>
84  
85 Receive the input date and return its SHA-256 digest encoded as a binary string.
86  
87 =head2 sha256_hex
88  
89 C<static method sha256_hex : string ($data : string);>
90  
91 Receive the input date and return its SHA-256 digest encoded as a hexadecimal string.
92  
93 =head2 sha256_base64
94  
95 C<static method sha256_base64 : string ($data : string);>
96  
97 Receive the input date and return its SHA-256 digest encoded as a Base64 string.
98  
99 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
100  
101 =head2 sha384
102  
103 C<static method sha384 : string ($data : string);>
104  
105 Receive the input date and return its SHA-384 digest encoded as a binary string.
106  
107 =head2 sha384_hex
108  
109 C<static method sha384_hex : string ($data : string);>
110  
111 Receive the input date and return its SHA-384 digest encoded as a hexadecimal string.
112  
113 =head2 sha384_base64
114  
115 C<static method sha384_base64 : string ($data : string);>
116  
117 Receive the input date and return its SHA-384 digest encoded as a Base64 string.
118  
119 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
120  
121 =head2 sha512
122  
123 C<static method sha512 : string ($data : string);>
124  
125 Receive the input date and return its SHA-512 digest encoded as a binary string.
126  
127 =head2 sha512_hex
128  
129 C<static method sha512_hex : string ($data : string);>
130  
131 Receive the input date and return its SHA-512 digest encoded as a hexadecimal string.
132  
133 =head2 sha512_base64
134  
135 C<static method sha512_base64 : string ($data : string);>
136  
137 Receive the input date and return its SHA-512 digest encoded as a Base64 string.
138  
139 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
140  
141 =head2 sha512224
142  
143 C<static method sha512224 : string ($data : string);>
144  
145 Receive the input date and return its SHA-512/224 digest encoded as a binary string.
146  
147 =head2 sha512224_hex
148  
149 C<static method sha512224_hex : string ($data : string);>
150  
151 Receive the input date and return its SHA-512/224 digest encoded as a hexadecimal string.
152  
153 =head2 sha512224_base64
154  
155 C<static method sha512224_base64 : string ($data : string);>
156  
157 Receive the input date and return its SHA-512/224 digest encoded as a Base64 string.
158  
159 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
160  
161 =head2 sha512256
162  
163 C<static method sha512256 : string ($data : string);>
164  
165 Receive the input date and return its SHA-512/256 digest encoded as a binary string.
166  
167 =head2 sha512256_hex
168  
169 C<static method sha512256_hex : string ($data : string);>
170  
171 Receive the input date and return its SHA-512/256 digest encoded as a hexadecimal string.
172  
173 =head2 sha512256_base64
174  
175 C<static method sha512256_base64 : string ($data : string);>
176  
177 Receive the input date and return its SHA-512/256 digest encoded as a Base64 string.
178  
179 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
180  
181 =head2 hmac_sha1
182  
183 C<static method hmac_sha1 : string ($data : string, $key : string);>
184  
185 Receive the input date and return its HMAC-SHA-1 digest encoded as a binary string.
186  
187 =head2 hmac_sha1_hex
188  
189 C<static method hmac_sha1_hex : string ($data : string, $key : string);>
190  
191 Receive the input date and return its HMAC-SHA-1 digest encoded as a hexadecimal string.
192  
193 =head2 hmac_sha1_base64
194  
195 C<static method hmac_sha1_base64 : string ($data : string, $key : string);>
196  
197 Receive the input date and return its HMAC-SHA-1 digest encoded as a Base64 string.
198  
199 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
200  
201 =head2 hmac_sha224
202  
203 C<static method hmac_sha224 : string ($data : string, $key : string);>
204  
205 Receive the input date and return its HMAC-SHA-224 digest encoded as a binary string.
206  
207 =head2 hmac_sha224_hex
208  
209 C<static method hmac_sha224_hex : string ($data : string, $key : string);>
210  
211 Receive the input date and return its HMAC-SHA-224 digest encoded as a hexadecimal string.
212  
213 =head2 hmac_sha224_base64
214  
215 C<static method hmac_sha224_base64 : string ($data : string, $key : string);>
216  
217 Receive the input date and return its HMAC-SHA-224 digest encoded as a Base64 string.
218  
219 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
220  
221 =head2 hmac_sha256
222  
223 C<static method hmac_sha256 : string ($data : string, $key : string);>
224  
225 Receive the input date and return its HMAC-SHA-256 digest encoded as a binary string.
226  
227 =head2 hmac_sha256_hex
228  
229 C<static method hmac_sha256_hex : string ($data : string, $key : string);>
230  
231 Receive the input date and return its HMAC-SHA-256 digest encoded as a hexadecimal string.
232  
233 =head2 hmac_sha256_base64
234  
235 C<static method hmac_sha256_base64 : string ($data : string, $key : string);>
236  
237 Receive the input date and return its HMAC-SHA-256 digest encoded as a Base64 string.
238  
239 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
240  
241 =head2 hmac_sha384
242  
243 C<static method hmac_sha384 : string ($data : string, $key : string);>
244  
245 Receive the input date and return its HMAC-SHA-384 digest encoded as a binary string.
246  
247 =head2 hmac_sha384_hex
248  
249 C<static method hmac_sha384_hex : string ($data : string, $key : string);>
250  
251 Receive the input date and return its HMAC-SHA-384 digest encoded as a hexadecimal string.
252  
253 =head2 hmac_sha384_base64
254  
255 C<static method hmac_sha384_base64 : string ($data : string, $key : string);>
256  
257 Receive the input date and return its HMAC-SHA-384 digest encoded as a Base64 string.
258  
259 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
260  
261 =head2 hmac_sha512
262  
263 C<static method hmac_sha512 : string ($data : string, $key : string);>
264  
265 Receive the input date and return its HMAC-SHA-512 digest encoded as a binary string.
266  
267 =head2 hmac_sha512_hex
268  
269 C<static method hmac_sha512_hex : string ($data : string, $key : string);>
270  
271 Receive the input date and return its HMAC-SHA-512 digest encoded as a hexadecimal string.
272  
273 =head2 hmac_sha512_base64
274  
275 C<static method hmac_sha512_base64 : string ($data : string, $key : string);>
276  
277 Receive the input date and return its HMAC-SHA-512 digest encoded as a Base64 string.
278  
279 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
280  
281 =head2 hmac_sha512224
282  
283 C<static method hmac_sha512224 : string ($data : string, $key : string);>
284  
285 Receive the input date and return its HMAC-SHA-512/224 digest encoded as a binary string.
286  
287 =head2 hmac_sha512224_hex
288  
289 C<static method hmac_sha512224_hex : string ($data : string, $key : string);>
290  
291 Receive the input date and return its HMAC-SHA-512/224 digest encoded as a hexadecimal string.
292  
293 =head2 hmac_sha512224_base64
294  
295 C<static method hmac_sha512224_base64 : string ($data : string, $key : string);>
296  
297 Receive the input date and return its HMAC-SHA-512/224 digest encoded as a Base64 string.
298  
299 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
300  
301 =head2 hmac_sha512256
302  
303 C<static method hmac_sha512256 : string ($data : string, $key : string);>
304  
305 Receive the input date and return its HMAC-SHA-512/256 digest encoded as a binary string.
306  
307 =head2 hmac_sha512256_hex
308  
309 C<static method hmac_sha512256_hex : string ($data : string, $key : string);>
310  
311 Receive the input date and return its HMAC-SHA-512/256 digest encoded as a hexadecimal string.
312  
313 =head2 hmac_sha512256_base64
314  
315 C<static method hmac_sha512256_base64 : string ($data : string, $key : string);>
316  
317 Receive the input date and return its HMAC-SHA-512/256 digest encoded as a Base64 string.
318  
319 See L<Digest::SHA/"PADDING OF BASE64 DIGESTS"> for details about padding.
320  
321 =head2 new
322  
323 C<static method new : L<Digest::SHA|SPVM::Digest::SHA> ($alg : int);>
324  
325 Returns a new C<Digest::SHA> object. Allowed values for I<$alg> are 1,
326 224, 256, 384, 512, 512224, or 512256. It's also possible to use
327 common string representations of the algorithm (e.g. "sha256",
328 "SHA-384"). If the argument is missing, SHA-1 will be used by
329 default.
330  
331 =head1 Instance Methods
332  
333 =head2 hashsize
334  
335 C<method hashsize : int ();>
336  
337 Returns the number of digest bits for this object. The values are
338 160, 224, 256, 384, 512, 224, and 256 for SHA-1, SHA-224, SHA-256,
339 SHA-384, SHA-512, SHA-512/224 and SHA-512/256, respectively.
340  
341 =head2 algorithm
342  
343 C<method algorithm : int ();>
344  
345 Returns the digest algorithm for this object. The values are 1,
346 224, 256, 384, 512, 512224, and 512256 for SHA-1, SHA-224, SHA-256,
347 SHA-384, SHA-512, SHA-512/224, and SHA-512/256, respectively.
348  
349 =head2 add
350  
351 C<method add : void ($date : string);>
352  
353 Use the input data to
354 update the current digest state. In other words, the following
355 statements have the same effect:
356  
357 $sha->add("a"); $sha->add("b"); $sha->add("c");
358 $sha->add("abc");
359  
360 =head2 digest
361  
362 C<method digest : string ();>
363  
364 Returns the digest encoded as a binary string.
365  
366 =head2 b64digest
367  
368 C<method hexdigest : string ();>
369  
370 Returns the digest encoded as a hexadecimal string.
371  
372 =head2 b64digest
373  
374 C<method b64digest : string ();>
375  
376 Returns the digest encoded as a Base64 string.
377  
378 =head2
379  
380 C<method clone : L<Digest::SHA|SPVM::Digest::SHA> ();>
381  
382 Returns a duplicate copy of the object.
383  
384 =head1 See Also
385  
386 =head2 Digest::SHA
387  
388 C<SPVM::Digest::SHA> is a Perl's L<Digest::SHA> porting to L<SPVM>.
389  
390 =head1 Repository
391  
392 L<SPVM::Digest::SHA - Github|https://github.com/yuki-kimoto/SPVM-Digest-SHA>
393  
394 =head1 Author
395  
396 Yuki Kimoto C<kimoto.yuki@gmail.com>
397  
398 =head1 Contributors
399  
400 L<Yoshiyuki Itoh|https://github.com/YoshiyukiItoh>
401  
402 =head1 Copyright & License
403  
404 Copyright (c) 2023 Yuki Kimoto
405  
406 MIT License
407  
↑ Summary