A sequence of 32 bytes, representing the SHA-256 hash. Hashes are used to refer to objects, trees, and actors.

Instance creation

Hash hash = Hash.from(hexString);
var hash = cds.hashFromHex(hexString);
my $hash = CDS::Hash->fromHex($hexString);

Creates an instance representing a 64-digit hex string. This function returns nullundef if the string does not contain a valid hex sequence, or if the length does not match.

Hash hash = Hash.from(bytes);
var hash = cds.hashFromBytes(bytes);
my $hash = CDS::Hash->from($bytes);

Creates an instance using the passed 32 bytes. This function returns nullundef if the length of bytes is not exactly 32.

Calculating hashes

		Hash hash = Hash.calculateFor(bytes);
		Hash hash = Hash.calculateFor(bytes.slice(offset, length));
		var hash = cds.hashForBytes(bytes);
		var hash = cds.hashForBytes(cds.slice(bytes, offset, length));
		my $hash = CDS::Hash->calculateFor($bytes);
		my $hash = CDS::Hash->calculateFor(substr($bytes, $offset, $length));

Calculates the SHA-256 hash of bytes (or a slice of it), and returns the corresponding hash instance.

Accessing the hash bytes

Bytes bytes = hash.bytes;
var bytes = hash.bytes
my $bytes = $hash->bytes;

Returns the 32 bytes of the hash.

See also

Calculating object hashes