load#

Construct a Digest::SHA object from a text state file written by dump.

Reads the file, parses its contents as a text state string, and returns a new object with the algorithm and internal state recorded in the file. Typically called as a class method, but works as an instance method too (the receiver is overwritten in place and returned, as with putstate).

Synopsis#

my $sha = Digest::SHA->load("hash.state");

What you get back#

A Digest::SHA object on success, undef if the file could not be read or the contents could not be parsed.

Examples#

my $sha = Digest::SHA->new(256);
$sha->add("one");
$sha->dump("hash.state");

my $resumed = Digest::SHA->load("hash.state");
$resumed->add("two");
print $resumed->hexdigest;
# same as Digest::SHA->new(256)->add("one")->add("two")->hexdigest
# Missing file returns undef rather than croaking:
my $sha = Digest::SHA->load("/does/not/exist");
print defined $sha ? "ok" : "undef"; # undef
# Works as an instance method too (and overwrites the receiver):
my $dummy = Digest::SHA->new(1);
my $sha = $dummy->load("hash.state");

Edge cases#

  • I/O failure or a parse error returns undef.

  • The returned object’s algorithm comes from the file, not from any receiver.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • dump - writes the file load reads.

  • putstate - parses the text state directly from a string.

  • _putstate - binary-state counterpart.