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.