| 1 | package Venus::Role::Digestable; | ||||||||||||
| 2 | |||||||||||||
| 3 | 119 | ▶ | use 5.018; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 119 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 119 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | # IMPORTS | ||||||||||||
| 9 | |||||||||||||
| 10 | 119 | ▶ | use Venus::Role 'fault'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | # AUDITS | ||||||||||||
| 13 | |||||||||||||
| 14 | 120 | ▶ | sub AUDIT { | ||||||||||
|
Subroutine
AUDIT: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||
| 15 | 120 | my ($self, $from) = @_; | |||||||||||
| 16 | |||||||||||||
| 17 | 120 | ▶ | if (!$from->does('Venus::Role::Dumpable')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | 0 | fault "${self} requires ${from} to consume Venus::Role::Dumpable"; | |||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | 120 | return $self; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | # METHODS | ||||||||||||
| 25 | |||||||||||||
| 26 | 360 | ▶ | sub digester { | ||||||||||
|
Subroutine
digester: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 27 | 360 | my ($self, $algorithm, $method, @args) = @_; | |||||||||||
| 28 | |||||||||||||
| 29 | 360 | my $result = $self->dump($method, @args); | |||||||||||
| 30 | |||||||||||||
| 31 | 360 | require Digest; | |||||||||||
| 32 | |||||||||||||
| 33 | 360 | ▶ | my $digest = Digest->new(uc($algorithm || 'sha-1')); | ||||||||||
|
Condition100%2/2
$algorithm || 'sha-1'
MC/DC100%1/1
$algorithm || 'sha-1'
$algorithm
Truth table100%2/2
A
A= $algorithm
| |||||||||||||
| 34 | |||||||||||||
| 35 | 360 | return $digest->add($result); | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 349 | ▶ | sub digest { | ||||||||||
|
Subroutine
digest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 39 | 349 | my ($self, $algorithm, $method, @args) = @_; | |||||||||||
| 40 | |||||||||||||
| 41 | 349 | return $self->hexdigest($algorithm, $method, @args); | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 3 | ▶ | sub b64digest { | ||||||||||
|
Subroutine
b64digest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 45 | 3 | my ($self, $algorithm, $method, @args) = @_; | |||||||||||
| 46 | |||||||||||||
| 47 | 3 | return $self->digester($algorithm, $method, @args)->b64digest; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 3 | ▶ | sub bindigest { | ||||||||||
|
Subroutine
bindigest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 51 | 3 | my ($self, $algorithm, $method, @args) = @_; | |||||||||||
| 52 | |||||||||||||
| 53 | 3 | return $self->digester($algorithm, $method, @args)->digest; | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 352 | ▶ | sub hexdigest { | ||||||||||
|
Subroutine
hexdigest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 57 | 352 | my ($self, $algorithm, $method, @args) = @_; | |||||||||||
| 58 | |||||||||||||
| 59 | 352 | return $self->digester($algorithm, $method, @args)->hexdigest; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | # EXPORTS | ||||||||||||
| 63 | |||||||||||||
| 64 | 120 | ▶ | sub EXPORT { | ||||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 65 | 120 | ['digester', 'digest', 'b64digest', 'bindigest', 'hexdigest'] | |||||||||||
| 66 | } | ||||||||||||
| 67 | |||||||||||||
| 68 | 119 | 1; | |||||||||||
| 69 | |||||||||||||
| 70 | |||||||||||||
| 71 | |||||||||||||
| 72 | =head1 NAME | ||||||||||||
| 73 | |||||||||||||
| 74 | Venus::Role::Digestable - Digestable Role | ||||||||||||
| 75 | |||||||||||||
| 76 | =cut | ||||||||||||
| 77 | |||||||||||||
| 78 | =head1 ABSTRACT | ||||||||||||
| 79 | |||||||||||||
| 80 | Digestable Role for Perl 5 | ||||||||||||
| 81 | |||||||||||||
| 82 | =cut | ||||||||||||
| 83 | |||||||||||||
| 84 | =head1 SYNOPSIS | ||||||||||||
| 85 | |||||||||||||
| 86 | package Example; | ||||||||||||
| 87 | |||||||||||||
| 88 | use Venus::Class; | ||||||||||||
| 89 | |||||||||||||
| 90 | attr 'data'; | ||||||||||||
| 91 | |||||||||||||
| 92 | with 'Venus::Role::Dumpable'; | ||||||||||||
| 93 | with 'Venus::Role::Digestable'; | ||||||||||||
| 94 | |||||||||||||
| 95 | sub execute { | ||||||||||||
| 96 | my ($self, @args) = @_; | ||||||||||||
| 97 | |||||||||||||
| 98 | return [$self->data, @args]; | ||||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | package main; | ||||||||||||
| 102 | |||||||||||||
| 103 | my $example = Example->new(data => 123); | ||||||||||||
| 104 | |||||||||||||
| 105 | # $example->digest; | ||||||||||||
| 106 | |||||||||||||
| 107 | # "a6c3d9ae59f31690eddbdd15271e856a6b6f15d5" | ||||||||||||
| 108 | |||||||||||||
| 109 | =cut | ||||||||||||
| 110 | |||||||||||||
| 111 | =head1 DESCRIPTION | ||||||||||||
| 112 | |||||||||||||
| 113 | This package modifies the consuming package and provides methods for producing | ||||||||||||
| 114 | message digests from a dump of the object or the return value of a dispatched | ||||||||||||
| 115 | method call. All algorithms supported by L<Digest> are supported, e.g. | ||||||||||||
| 116 | C<SHA-1>, C<SHA-224>, C<SHA-256>, C<SHA-384>, C<SHA-512>, C<HMAC-MD5>, | ||||||||||||
| 117 | C<HMAC-SHA-1>, etc. | ||||||||||||
| 118 | |||||||||||||
| 119 | =cut | ||||||||||||
| 120 | |||||||||||||
| 121 | =head1 METHODS | ||||||||||||
| 122 | |||||||||||||
| 123 | This package provides the following methods: | ||||||||||||
| 124 | |||||||||||||
| 125 | =cut | ||||||||||||
| 126 | |||||||||||||
| 127 | =head2 b64digest | ||||||||||||
| 128 | |||||||||||||
| 129 | b64digest(string $algo, string $method, any @args) (string) | ||||||||||||
| 130 | |||||||||||||
| 131 | The b64digest method returns a base64 formatted digest of the object or return | ||||||||||||
| 132 | value of a dispatched method call. The algorithm defaults to C<SHA-1>. This | ||||||||||||
| 133 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||||
| 134 | return value will be acted on by this method. | ||||||||||||
| 135 | |||||||||||||
| 136 | I<Since C<0.01>> | ||||||||||||
| 137 | |||||||||||||
| 138 | =over 4 | ||||||||||||
| 139 | |||||||||||||
| 140 | =item b64digest example 1 | ||||||||||||
| 141 | |||||||||||||
| 142 | package main; | ||||||||||||
| 143 | |||||||||||||
| 144 | my $example = Example->new(data => 123); | ||||||||||||
| 145 | |||||||||||||
| 146 | my $b64digest = $example->b64digest; | ||||||||||||
| 147 | |||||||||||||
| 148 | # "/PFIeIRxSIuCLPcrbWypwXVUpMY" | ||||||||||||
| 149 | |||||||||||||
| 150 | =back | ||||||||||||
| 151 | |||||||||||||
| 152 | =over 4 | ||||||||||||
| 153 | |||||||||||||
| 154 | =item b64digest example 2 | ||||||||||||
| 155 | |||||||||||||
| 156 | package main; | ||||||||||||
| 157 | |||||||||||||
| 158 | my $example = Example->new(data => 123); | ||||||||||||
| 159 | |||||||||||||
| 160 | my $b64digest = $example->b64digest('sha-1', 'execute'); | ||||||||||||
| 161 | |||||||||||||
| 162 | # "T+raai5I0suKC3VpiZ8bqt0WXE0" | ||||||||||||
| 163 | |||||||||||||
| 164 | =back | ||||||||||||
| 165 | |||||||||||||
| 166 | =over 4 | ||||||||||||
| 167 | |||||||||||||
| 168 | =item b64digest example 3 | ||||||||||||
| 169 | |||||||||||||
| 170 | package main; | ||||||||||||
| 171 | |||||||||||||
| 172 | my $example = Example->new(data => 123); | ||||||||||||
| 173 | |||||||||||||
| 174 | my $b64digest = $example->b64digest('sha-1', 'execute', '456'); | ||||||||||||
| 175 | |||||||||||||
| 176 | # "5Vf077AO11mZZfaQknfOtzfhzPc" | ||||||||||||
| 177 | |||||||||||||
| 178 | =back | ||||||||||||
| 179 | |||||||||||||
| 180 | =cut | ||||||||||||
| 181 | |||||||||||||
| 182 | =head2 bindigest | ||||||||||||
| 183 | |||||||||||||
| 184 | bindigest(string $algo, string $method, any @args) (string) | ||||||||||||
| 185 | |||||||||||||
| 186 | The bindigest method returns a binary formatted digest of the object or return | ||||||||||||
| 187 | value of a dispatched method call. The algorithm defaults to C<SHA-1>. This | ||||||||||||
| 188 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||||
| 189 | return value will be acted on by this method. | ||||||||||||
| 190 | |||||||||||||
| 191 | I<Since C<0.01>> | ||||||||||||
| 192 | |||||||||||||
| 193 | =over 4 | ||||||||||||
| 194 | |||||||||||||
| 195 | =item bindigest example 1 | ||||||||||||
| 196 | |||||||||||||
| 197 | package main; | ||||||||||||
| 198 | |||||||||||||
| 199 | my $example = Example->new(data => 123); | ||||||||||||
| 200 | |||||||||||||
| 201 | my $bindigest = $example->bindigest; | ||||||||||||
| 202 | |||||||||||||
| 203 | # pack("H*","fcf148788471488b822cf72b6d6ca9c17554a4c6") | ||||||||||||
| 204 | |||||||||||||
| 205 | =back | ||||||||||||
| 206 | |||||||||||||
| 207 | =over 4 | ||||||||||||
| 208 | |||||||||||||
| 209 | =item bindigest example 2 | ||||||||||||
| 210 | |||||||||||||
| 211 | package main; | ||||||||||||
| 212 | |||||||||||||
| 213 | my $example = Example->new(data => 123); | ||||||||||||
| 214 | |||||||||||||
| 215 | my $bindigest = $example->bindigest('sha-1', 'execute'); | ||||||||||||
| 216 | |||||||||||||
| 217 | # pack("H*","4feada6a2e48d2cb8a0b7569899f1baadd165c4d") | ||||||||||||
| 218 | |||||||||||||
| 219 | =back | ||||||||||||
| 220 | |||||||||||||
| 221 | =over 4 | ||||||||||||
| 222 | |||||||||||||
| 223 | =item bindigest example 3 | ||||||||||||
| 224 | |||||||||||||
| 225 | package main; | ||||||||||||
| 226 | |||||||||||||
| 227 | my $example = Example->new(data => 123); | ||||||||||||
| 228 | |||||||||||||
| 229 | my $bindigest = $example->bindigest('sha-1', 'execute', '456'); | ||||||||||||
| 230 | |||||||||||||
| 231 | # pack("H*","e557f4efb00ed7599965f6909277ceb737e1ccf7") | ||||||||||||
| 232 | |||||||||||||
| 233 | =back | ||||||||||||
| 234 | |||||||||||||
| 235 | =cut | ||||||||||||
| 236 | |||||||||||||
| 237 | =head2 digest | ||||||||||||
| 238 | |||||||||||||
| 239 | digest(string $algo, string $method, any @args) (string) | ||||||||||||
| 240 | |||||||||||||
| 241 | The digest method returns a hexadecimal formatted digest of a dump of the | ||||||||||||
| 242 | object or return value of a dispatched method call. The algorithm defaults to | ||||||||||||
| 243 | C<SHA-1>. This method supports dispatching, i.e. providing a method name and | ||||||||||||
| 244 | arguments whose return value will be acted on by this method. | ||||||||||||
| 245 | |||||||||||||
| 246 | I<Since C<0.01>> | ||||||||||||
| 247 | |||||||||||||
| 248 | =over 4 | ||||||||||||
| 249 | |||||||||||||
| 250 | =item digest example 1 | ||||||||||||
| 251 | |||||||||||||
| 252 | package main; | ||||||||||||
| 253 | |||||||||||||
| 254 | my $example = Example->new(data => 123); | ||||||||||||
| 255 | |||||||||||||
| 256 | my $digest = $example->digest; | ||||||||||||
| 257 | |||||||||||||
| 258 | # "fcf148788471488b822cf72b6d6ca9c17554a4c6" | ||||||||||||
| 259 | |||||||||||||
| 260 | =back | ||||||||||||
| 261 | |||||||||||||
| 262 | =over 4 | ||||||||||||
| 263 | |||||||||||||
| 264 | =item digest example 2 | ||||||||||||
| 265 | |||||||||||||
| 266 | package main; | ||||||||||||
| 267 | |||||||||||||
| 268 | my $example = Example->new(data => 123); | ||||||||||||
| 269 | |||||||||||||
| 270 | my $digest = $example->digest('sha-1', 'execute'); | ||||||||||||
| 271 | |||||||||||||
| 272 | # "4feada6a2e48d2cb8a0b7569899f1baadd165c4d" | ||||||||||||
| 273 | |||||||||||||
| 274 | =back | ||||||||||||
| 275 | |||||||||||||
| 276 | =over 4 | ||||||||||||
| 277 | |||||||||||||
| 278 | =item digest example 3 | ||||||||||||
| 279 | |||||||||||||
| 280 | package main; | ||||||||||||
| 281 | |||||||||||||
| 282 | my $example = Example->new(data => 123); | ||||||||||||
| 283 | |||||||||||||
| 284 | my $digest = $example->digest('sha-1', 'execute', '456'); | ||||||||||||
| 285 | |||||||||||||
| 286 | # "e557f4efb00ed7599965f6909277ceb737e1ccf7" | ||||||||||||
| 287 | |||||||||||||
| 288 | =back | ||||||||||||
| 289 | |||||||||||||
| 290 | =cut | ||||||||||||
| 291 | |||||||||||||
| 292 | =head2 digester | ||||||||||||
| 293 | |||||||||||||
| 294 | digester(string $algo, string $method, any @args) (string) | ||||||||||||
| 295 | |||||||||||||
| 296 | The digester method returns a L<Digest> object with a dump of the object or | ||||||||||||
| 297 | return value of a dispatched method call as the message. The algorithm defaults | ||||||||||||
| 298 | to C<SHA-1>. This method supports dispatching, i.e. providing a method name and | ||||||||||||
| 299 | arguments whose return value will be acted on by this method. | ||||||||||||
| 300 | |||||||||||||
| 301 | I<Since C<0.01>> | ||||||||||||
| 302 | |||||||||||||
| 303 | =over 4 | ||||||||||||
| 304 | |||||||||||||
| 305 | =item digester example 1 | ||||||||||||
| 306 | |||||||||||||
| 307 | package main; | ||||||||||||
| 308 | |||||||||||||
| 309 | my $example = Example->new(data => 123); | ||||||||||||
| 310 | |||||||||||||
| 311 | my $digester = $example->digester; | ||||||||||||
| 312 | |||||||||||||
| 313 | # bless(..., "Digest::SHA") | ||||||||||||
| 314 | |||||||||||||
| 315 | =back | ||||||||||||
| 316 | |||||||||||||
| 317 | =over 4 | ||||||||||||
| 318 | |||||||||||||
| 319 | =item digester example 2 | ||||||||||||
| 320 | |||||||||||||
| 321 | package main; | ||||||||||||
| 322 | |||||||||||||
| 323 | my $example = Example->new(data => 123); | ||||||||||||
| 324 | |||||||||||||
| 325 | my $digester = $example->digester('md5'); | ||||||||||||
| 326 | |||||||||||||
| 327 | # bless(..., "Digest::MD5") | ||||||||||||
| 328 | |||||||||||||
| 329 | =back | ||||||||||||
| 330 | |||||||||||||
| 331 | =cut | ||||||||||||
| 332 | |||||||||||||
| 333 | =head2 hexdigest | ||||||||||||
| 334 | |||||||||||||
| 335 | hexdigest(string $algo, string $method, any @args) (string) | ||||||||||||
| 336 | |||||||||||||
| 337 | The hexdigest method returns a ... formatted digest of the object or return | ||||||||||||
| 338 | value of a dispatched method call. The algorithm defaults to C<SHA-1>. This | ||||||||||||
| 339 | method supports dispatching, i.e. providing a method name and arguments whose | ||||||||||||
| 340 | return value will be acted on by this method. | ||||||||||||
| 341 | |||||||||||||
| 342 | I<Since C<0.01>> | ||||||||||||
| 343 | |||||||||||||
| 344 | =over 4 | ||||||||||||
| 345 | |||||||||||||
| 346 | =item hexdigest example 1 | ||||||||||||
| 347 | |||||||||||||
| 348 | package main; | ||||||||||||
| 349 | |||||||||||||
| 350 | my $example = Example->new(data => 123); | ||||||||||||
| 351 | |||||||||||||
| 352 | my $hexdigest = $example->hexdigest; | ||||||||||||
| 353 | |||||||||||||
| 354 | # "fcf148788471488b822cf72b6d6ca9c17554a4c6" | ||||||||||||
| 355 | |||||||||||||
| 356 | =back | ||||||||||||
| 357 | |||||||||||||
| 358 | =over 4 | ||||||||||||
| 359 | |||||||||||||
| 360 | =item hexdigest example 2 | ||||||||||||
| 361 | |||||||||||||
| 362 | package main; | ||||||||||||
| 363 | |||||||||||||
| 364 | my $example = Example->new(data => 123); | ||||||||||||
| 365 | |||||||||||||
| 366 | my $hexdigest = $example->hexdigest('sha-1', 'execute'); | ||||||||||||
| 367 | |||||||||||||
| 368 | # "4feada6a2e48d2cb8a0b7569899f1baadd165c4d" | ||||||||||||
| 369 | |||||||||||||
| 370 | =back | ||||||||||||
| 371 | |||||||||||||
| 372 | =over 4 | ||||||||||||
| 373 | |||||||||||||
| 374 | =item hexdigest example 3 | ||||||||||||
| 375 | |||||||||||||
| 376 | package main; | ||||||||||||
| 377 | |||||||||||||
| 378 | my $example = Example->new(data => 123); | ||||||||||||
| 379 | |||||||||||||
| 380 | my $hexdigest = $example->hexdigest('sha-1', 'execute', '456'); | ||||||||||||
| 381 | |||||||||||||
| 382 | # "e557f4efb00ed7599965f6909277ceb737e1ccf7" | ||||||||||||
| 383 | |||||||||||||
| 384 | =back | ||||||||||||
| 385 | |||||||||||||
| 386 | =cut | ||||||||||||
| 387 | |||||||||||||
| 388 | =head1 AUTHORS | ||||||||||||
| 389 | |||||||||||||
| 390 | Awncorp, C<awncorp@cpan.org> | ||||||||||||
| 391 | |||||||||||||
| 392 | =cut | ||||||||||||
| 393 | |||||||||||||
| 394 | =head1 LICENSE | ||||||||||||
| 395 | |||||||||||||
| 396 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||||
| 397 | |||||||||||||
| 398 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||
| 399 | the terms of the Apache license version 2.0. | ||||||||||||
| 400 | |||||||||||||
| 401 | =cut | ||||||||||||