```{index} single: reset; Digest::SHA function ``` ```{index} single: Digest::SHA::reset; Perl function ``` # 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"`). ## Synopsis ```perl $sha->reset; # rewind, keep algorithm $sha->reset(512); # rewind and switch to SHA-512 $sha->reset("SHA-384"); # string form ``` ## What you get back The receiver on success (chainable), or `undef` if an algorithm argument was supplied that could not be parsed. ## Examples ```perl 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; ``` ```perl my $sha = Digest::SHA->new(256); $sha->reset(512)->add("hello"); print $sha->algorithm; # 512 ``` ```perl my $sha = Digest::SHA->new(256); my $ok = $sha->reset("bogus"); # undef ``` ## Edge cases - Called on a non-`Digest::SHA` object, returns `undef`. - After the built-in auto-reset inside `digest`, calling `reset` explicitly is harmless. ## Differences from upstream Fully compatible with upstream `Digest::SHA` {{ upstream.Digest_SHA }}. ## See also - `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.