TreeHash
in package
implements
ChunkHashInterface
Encapsulates the creation of a tree hash from streamed chunks of data
Table of Contents
Interfaces
- ChunkHashInterface
- Interface for objects that encapsulate the creation of a hash from streamed chunks of data
Properties
- $algorithm : string
- $checksums : array<string|int, mixed>
- $hash : string
- $hashRaw : string
Methods
- __construct() : self
- Constructs the chunk hash and sets the algorithm to use for hashing
- addChecksum() : self
- Add a checksum to the tree hash directly
- addData() : self
- Add a chunk of data to be hashed
- fromChecksums() : TreeHash
- Create a tree hash from an array of existing tree hash checksums
- fromContent() : TreeHash
- Create a tree hash from a content body
- getChecksums() : array<string|int, mixed>
- getHash() : string
- Return the results of the hash
- validateChecksum() : bool
- Validates an entity body with a tree hash checksum
Properties
$algorithm
protected
string
$algorithm
The algorithm used for hashing
$checksums
protected
array<string|int, mixed>
$checksums
= array()
Set of binary checksums from which the tree hash is derived
$hash
protected
string
$hash
The resulting hash in hex form
$hashRaw
protected
string
$hashRaw
The resulting hash in binary form
Methods
__construct()
Constructs the chunk hash and sets the algorithm to use for hashing
public
__construct([mixed $algorithm = self::DEFAULT_ALGORITHM ]) : self
Parameters
- $algorithm : mixed = self::DEFAULT_ALGORITHM
-
A valid hash algorithm name as returned by
hash_algos()
Return values
selfaddChecksum()
Add a checksum to the tree hash directly
public
addChecksum(string $checksum[, bool $inBinaryForm = false ]) : self
Parameters
- $checksum : string
-
The checksum to add
- $inBinaryForm : bool = false
-
Whether or not the checksum is already in binary form
Tags
Return values
selfaddData()
Add a chunk of data to be hashed
public
addData(mixed $data) : self
Parameters
- $data : mixed
-
Data to be hashed
Tags
Return values
selffromChecksums()
Create a tree hash from an array of existing tree hash checksums
public
static fromChecksums(array<string|int, mixed> $checksums[, bool $inBinaryForm = false ][, string $algorithm = self::DEFAULT_ALGORITHM ]) : TreeHash
Parameters
- $checksums : array<string|int, mixed>
-
Set of checksums
- $inBinaryForm : bool = false
-
Whether or not the checksums are already in binary form
- $algorithm : string = self::DEFAULT_ALGORITHM
-
A valid hash algorithm name as returned by
hash_algos()
Return values
TreeHashfromContent()
Create a tree hash from a content body
public
static fromContent(string|resource|EntityBody $content[, string $algorithm = self::DEFAULT_ALGORITHM ]) : TreeHash
Parameters
- $content : string|resource|EntityBody
-
Content to create a tree hash for
- $algorithm : string = self::DEFAULT_ALGORITHM
-
A valid hash algorithm name as returned by
hash_algos()
Return values
TreeHashgetChecksums()
public
getChecksums() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of raw checksums composing the tree hash
getHash()
Return the results of the hash
public
getHash([mixed $returnBinaryForm = false ]) : string
Parameters
- $returnBinaryForm : mixed = false
-
If true, returns the hash in binary form instead of hex form
Return values
stringvalidateChecksum()
Validates an entity body with a tree hash checksum
public
static validateChecksum(string|resource|EntityBody $content, string $checksum[, string $algorithm = self::DEFAULT_ALGORITHM ]) : bool
Parameters
- $content : string|resource|EntityBody
-
Content to create a tree hash for
- $checksum : string
-
The checksum to use for validation
- $algorithm : string = self::DEFAULT_ALGORITHM
-
A valid hash algorithm name as returned by
hash_algos()