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.

Σύνοψη#

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

Τι επιστρέφεται#

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

Παραδείγματα#

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

Οριακές περιπτώσεις#

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

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

Διαφορές από το upstream#

Fully compatible with upstream Digest::SHA 6.04.

Δείτε επίσης#

  • 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.