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.
Σύνοψη#
$sha->_putstate($blob);
Τι επιστρέφεται#
The receiver on success, undef on failure (invalid length or bad object).
Παραδείγματα#
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);
Οριακές περιπτώσεις#
Blob length must match the receiver’s algorithm (116 vs 212 bytes); a mismatch returns
undef.Called on a non-
Digest::SHAobject, returnsundef.
Διαφορές από το upstream#
Fully compatible with upstream Digest::SHA 6.04.
Δείτε επίσης#
_getstate- produces the blob consumed here.putstate- text-based restore that also creates new objects.load- text-based file-loading counterpart.