Class TreeHash
Encapsulates the creation of a tree hash from streamed chunks of data
- Aws\Common\Hash\TreeHash implements Aws\Common\Hash\ChunkHashInterface
Methods summary
-
public static
fromChecksums ( array $checksums, bool $inBinaryForm = false, string $algorithm =
Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)Create a tree hash from an array of existing tree hash checksums
-
public static
fromContent ( string|resource|EntityBody $content, string $algorithm =
Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)Create a tree hash from a content body
-
public static
validateChecksum ( string|resource|EntityBody $content, string $checksum, string $algorithm =
Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)Validates an entity body with a tree hash checksum
-
public
__construct ( string $algorithm =
Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)Constructs the chunk hash and sets the algorithm to use for hashing
-
public
addData ( string $data )
Add a chunk of data to be hashed
-
public
addChecksum ( string $checksum, bool $inBinaryForm = false )
Add a checksum to the tree hash directly
-
public
getHash ( bool $returnBinaryForm = false )
Return the results of the hash
-
public
getChecksums ( )
Methods detail
public static
Aws\Common\Hash\TreeHash
fromChecksums( array $checksums, boolean $inBinaryForm = false, string $algorithm = Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)
Create a tree hash from an array of existing tree hash checksums
Parameters
- $checksums
array
$checksums Set of checksums- $inBinaryForm
boolean
$inBinaryForm Whether or not the checksums are already in binary form- $algorithm
string
$algorithm A valid hash algorithm name as returned byhash_algos()
Returns
public static
Aws\Common\Hash\TreeHash
fromContent( string|resource|Guzzle\Http\EntityBody
$content, string $algorithm = Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)
Create a tree hash from a content body
Parameters
- $content
string|resource|
Guzzle\Http\EntityBody
$content Content to create a tree hash for- $algorithm
string
$algorithm A valid hash algorithm name as returned byhash_algos()
Returns
public static
boolean
validateChecksum( string|resource|Guzzle\Http\EntityBody
$content, string $checksum, string $algorithm = Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)
Validates an entity body with a tree hash checksum
Parameters
- $content
string|resource|
Guzzle\Http\EntityBody
$content Content to create a tree hash for- $checksum
string
$checksum The checksum to use for validation- $algorithm
string
$algorithm A valid hash algorithm name as returned byhash_algos()
Returns
boolean
public
Aws\Common\Hash\TreeHash
__construct( string $algorithm = Aws\Common\Hash\ChunkHashInterface::DEFAULT_ALGORITHM
)
Constructs the chunk hash and sets the algorithm to use for hashing
Parameters
- $algorithm
string
$algorithm A valid hash algorithm name as returned byhash_algos()
Returns
Implementation of
Add a chunk of data to be hashed
Parameters
- $data
string
$data Data to be hashed
Returns
Throws
Aws\Common\Exception\LogicException
if the root tree hash is already calculated
Aws\Common\Exception\InvalidArgumentException
if the data is larger than 1MB
Implementation of
Add a checksum to the tree hash directly
Parameters
- $checksum
string
$checksum The checksum to add- $inBinaryForm
boolean
$inBinaryForm Whether or not the checksum is already in binary form
Returns
Throws
Return the results of the hash
Parameters
- $returnBinaryForm
boolean
$returnBinaryForm If true, returns the hash in binary form instead of hex form
Returns
string
Implementation of
Returns
array
Array of raw checksums composing the tree hash
Magic methods summary
Constants summary
Constants inherited from Aws\Common\Hash\ChunkHashInterface
Properties summary
protected
string
|
$algorithm |
#
The algorithm used for hashing |
protected
array
|
$checksums |
#
Set of binary checksums from which the tree hash is derived |
protected
string
|
$hash |
#
The resulting hash in hex form |
protected
string
|
$hashRaw |
#
The resulting hash in binary form |