algorithm#

Return the algorithm code of a Digest::SHA object.

The code is the same integer you can pass to new: 1, 224, 256, 384, 512, 512224, or 512256. Useful when a function receives a Digest::SHA object from elsewhere and needs to act differently based on which variant it is.

Synopsis#

my $code = $sha->algorithm;

What you get back#

An integer in the set {1, 224, 256, 384, 512, 512224, 512256}.

Examples#

my $sha = Digest::SHA->new("SHA-256");
print $sha->algorithm;   # 256
my $sha = Digest::SHA->new("SHA-512/224");
print $sha->algorithm;   # 512224
## Dispatch on algorithm:

my $code = $sha->algorithm;
my $name = $code == 1 ? "SHA-1" : "SHA-$code";

Edge cases#

  • Called on a non-Digest::SHA object, returns undef.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • hashsize — digest length in bits for this algorithm.

  • new — accepts the values returned here as its algorithm argument.