reset#

Rewind a Digest::SHA object, optionally switching algorithm.

Clears buffered data and restores the initial hash state so the same object can be reused for a fresh digest. With no argument the algorithm is preserved; with an algorithm argument the object is rewound and retargeted at that algorithm. Accepts the same algorithm shapes as new (integer code or string like "SHA-256").

Σύνοψη#

$sha->reset;             # rewind, keep algorithm
$sha->reset(512);        # rewind and switch to SHA-512
$sha->reset("SHA-384");  # string form

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

The receiver on success (chainable), or undef if an algorithm argument was supplied that could not be parsed.

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

my $sha = Digest::SHA->new(256);
$sha->add("first");
my $a = $sha->hexdigest;       # finalises and auto-resets already
$sha->reset;                   # defensive rewind before reuse
$sha->add("second");
my $b = $sha->hexdigest;
my $sha = Digest::SHA->new(256);
$sha->reset(512)->add("hello");
print $sha->algorithm;         # 512
my $sha = Digest::SHA->new(256);
my $ok = $sha->reset("bogus"); # undef

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

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

  • After the built-in auto-reset inside digest, calling reset explicitly is harmless.

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

Fully compatible with upstream Digest::SHA 6.04.

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

  • new - when called on an instance, functionally equivalent to reset.

  • digest - auto-rewinds after finalisation, so explicit reset is only needed when you abandon a computation partway.

  • clone - if you want a copy of the pre-reset state, clone first.