putstate#
Restore a Digest::SHA object’s state from a packed binary string.
The inverse of _getstate. Validates the length of the supplied blob
against the receiver’s algorithm and rewrites the internal hash state
in place. After a successful _putstate, feeding more data with add
continues the hash as if no break had occurred.
The receiver’s algorithm is not changed by this call; it must already match the algorithm the blob was produced under.
Synopsis#
$sha->_putstate($blob);
What you get back#
The receiver on success, undef on failure (invalid length or bad
object).
Examples#
my $a = Digest::SHA->new(256);
$a->add("first half");
my $blob = $a->_getstate;
my $b = Digest::SHA->new(256);
$b->_putstate($blob) or die "restore failed";
$b->add("second half");
print $b->hexdigest;
## Round-trip through a file:
open my $in, "<", "hash.state" or die $!;
binmode $in;
my $blob = do { local $/; <$in> };
my $sha = Digest::SHA->new(256);
$sha->_putstate($blob);
Edge cases#
Blob length must match the receiver’s algorithm (116 vs 212 bytes); a mismatch returns
undef.Called on a non-
Digest::SHAobject, returnsundef.
Differences from upstream#
Fully compatible with upstream Digest::SHA 6.04.
See also#
_getstate— produces the blob consumed here.putstate— text-based restore that also creates new objects.load— text-based file-loading counterpart.