newSHA#

Construct a fresh Digest::SHA object for the given algorithm number.

Low-level constructor that takes an algorithm code directly. Most code calls new instead; newSHA is the path that the XS layer exposes and that new eventually delegates to. Valid algorithm codes are 1, 224, 256, 384, 512, 512224, and 512256. Any other value returns undef instead of croaking.

Synopsis#

my $sha = Digest::SHA::newSHA("Digest::SHA", 256);

What you get back#

A blessed Digest::SHA object, ready to accept add, addfile, or digest calls. Returns undef on an unknown algorithm code.

Examples#

my $sha = Digest::SHA::newSHA("Digest::SHA", 512);
$sha->add("hello");
print $sha->hexdigest;
my $bad = Digest::SHA::newSHA("Digest::SHA", 999);
print defined $bad ? "ok" : "undef"; # undef

Edge cases#

  • Missing algorithm or missing class name croaks with a usage error.

  • Unknown algorithm code returns undef; check the return value before using it.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • new — higher-level constructor that accepts strings like "SHA-256".

  • clone — copy an existing context instead of starting over.

  • reset — reinitialise an existing object, optionally switching algorithm.