| 1 | package Crypt::Sodium::XS::hash; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Crypt::Sodium::XS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | _define_constants(); | |||||||||
| 9 | |||||||||||
| 10 | { | ||||||||||
| 11 | 1 | my @bases = qw( | |||||||||
| 12 | init | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 1 | my @constant_bases = qw( | |||||||||
| 16 | BYTES | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | my $default = [ | ||||||||||
| 20 | "hash", | ||||||||||
| 21 | 1 | (map { "hash_$_" } @bases), | |||||||||
| 22 | 1 | (map { "hash_$_" } @constant_bases, "PRIMITIVE"), | |||||||||
| 23 | ]; | ||||||||||
| 24 | my $sha256 = [ | ||||||||||
| 25 | "hash_sha256", | ||||||||||
| 26 | 1 | (map { "hash_sha256_$_" } @bases), | |||||||||
| 27 | 1 | (map { "hash_sha256_$_" } @constant_bases), | |||||||||
| 28 | ]; | ||||||||||
| 29 | my $sha512 = [ | ||||||||||
| 30 | "hash_sha512", | ||||||||||
| 31 | 1 | (map { "hash_sha512_$_" } @bases), | |||||||||
| 32 | 1 | (map { "hash_sha512_$_" } @constant_bases), | |||||||||
| 33 | ]; | ||||||||||
| 34 | my $sha3256 = [ | ||||||||||
| 35 | "hash_sha3256", | ||||||||||
| 36 | 1 | (map { "hash_sha3256_$_" } @bases), | |||||||||
| 37 | 1 | (map { "hash_sha3256_$_" } @constant_bases), | |||||||||
| 38 | ]; | ||||||||||
| 39 | my $sha3512 = [ | ||||||||||
| 40 | "hash_sha3512", | ||||||||||
| 41 | 1 | (map { "hash_sha3512_$_" } @bases), | |||||||||
| 42 | 1 | (map { "hash_sha3512_$_" } @constant_bases), | |||||||||
| 43 | ]; | ||||||||||
| 44 | 1 | my $features = ['hash_sha3_available']; | |||||||||
| 45 | |||||||||||
| 46 | 1 | our %EXPORT_TAGS = ( | |||||||||
| 47 | all => [ @$features, @$default, @$sha256, @$sha512 ], | ||||||||||
| 48 | features => $features, | ||||||||||
| 49 | default => $default, | ||||||||||
| 50 | sha2 => [ @$sha256, @$sha512 ], | ||||||||||
| 51 | sha256 => $sha256, | ||||||||||
| 52 | sha512 => $sha512, | ||||||||||
| 53 | sha3 => [ @$sha3256, @$sha3512 ], | ||||||||||
| 54 | sha3256 => $sha3256, | ||||||||||
| 55 | sha3512 => $sha3512, | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | 1 | our @EXPORT_OK = @{$EXPORT_TAGS{all}}; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 1 | *sha3_available = \&hash_sha3_available; | |||||||||
| 62 | |||||||||||
| 63 | package Crypt::Sodium::XS::OO::hash; | ||||||||||
| 64 | 1 | ▶ | use parent 'Crypt::Sodium::XS::OO::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 65 | |||||||||||
| 66 | my %methods = ( | ||||||||||
| 67 | default => { | ||||||||||
| 68 | BYTES => \&Crypt::Sodium::XS::hash::hash_BYTES, | ||||||||||
| 69 | PRIMITIVE => \&Crypt::Sodium::XS::hash::hash_PRIMITIVE, | ||||||||||
| 70 | hash => \&Crypt::Sodium::XS::hash::hash, | ||||||||||
| 71 | 0 | ▶ | init => sub { die "init is not supported for default primitive" }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 72 | }, | ||||||||||
| 73 | sha256 => { | ||||||||||
| 74 | BYTES => \&Crypt::Sodium::XS::hash::hash_sha256_BYTES, | ||||||||||
| 75 | 0 | ▶ | PRIMITIVE => sub { 'sha256' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 76 | hash => \&Crypt::Sodium::XS::hash::hash_sha256, | ||||||||||
| 77 | init => \&Crypt::Sodium::XS::hash::hash_sha256_init, | ||||||||||
| 78 | }, | ||||||||||
| 79 | sha512 => { | ||||||||||
| 80 | BYTES => \&Crypt::Sodium::XS::hash::hash_sha512_BYTES, | ||||||||||
| 81 | 0 | ▶ | PRIMITIVE => sub { 'sha512' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 82 | hash => \&Crypt::Sodium::XS::hash::hash_sha512, | ||||||||||
| 83 | init => \&Crypt::Sodium::XS::hash::hash_sha512_init, | ||||||||||
| 84 | }, | ||||||||||
| 85 | Crypt::Sodium::XS::hash->sha3_available ? ( | ||||||||||
| 86 | sha3256 => { | ||||||||||
| 87 | BYTES => \&Crypt::Sodium::XS::hash::hash_sha3256_BYTES, | ||||||||||
| 88 | 0 | ▶ | PRIMITIVE => sub { 'sha3256' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 89 | hash => \&Crypt::Sodium::XS::hash::hash_sha3256, | ||||||||||
| 90 | init => \&Crypt::Sodium::XS::hash::hash_sha3256_init, | ||||||||||
| 91 | }, | ||||||||||
| 92 | sha3512 => { | ||||||||||
| 93 | BYTES => \&Crypt::Sodium::XS::hash::hash_sha3512_BYTES, | ||||||||||
| 94 | 0 | ▶ | PRIMITIVE => sub { 'sha3512' }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 95 | 1 | ▶ | hash => \&Crypt::Sodium::XS::hash::hash_sha3512, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | init => \&Crypt::Sodium::XS::hash::hash_sha3512_init, | ||||||||||
| 97 | }, | ||||||||||
| 98 | ) : (), | ||||||||||
| 99 | ); | ||||||||||
| 100 | |||||||||||
| 101 | 6 | ▶ | sub Crypt::Sodium::XS::hash::primitives { keys %methods } | ||||||||
|
Subroutine
primitives: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 102 | 1 | *primitives = \&Crypt::Sodium::XS::hash::primitives; | |||||||||
| 103 | 1 | *sha3_available = \&Crypt::Sodium::XS::hash::sha3_available; | |||||||||
| 104 | |||||||||||
| 105 | 5 | ▶ | sub BYTES { my $self = shift; goto $methods{$self->{primitive}}->{BYTES}; } | ||||||||
|
Subroutine
BYTES: called CC=1 SCAR=0.0
| |||||||||||
| 106 | 0 | ▶ | sub PRIMITIVE { my $self = shift; goto $methods{$self->{primitive}}->{PRIMITIVE}; } | ||||||||
|
Subroutine
PRIMITIVE: not called CC=1 SCAR=6.9
| |||||||||||
| 107 | 10 | ▶ | sub hash { my $self = shift; goto $methods{$self->{primitive}}->{hash}; } | ||||||||
|
Subroutine
hash: called CC=1 SCAR=0.0
| |||||||||||
| 108 | 8 | ▶ | sub init { my $self = shift; goto $methods{$self->{primitive}}->{init}; } | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
| |||||||||||
| 109 | |||||||||||
| 110 | 1 | 1; | |||||||||
| 111 | |||||||||||
| 112 | __END__ | ||||||||||