NOTE: For Version 3 of the AWS SDK for PHP, please see the V3 User Guide and V3 API Reference.

# Class TreeHash

Encapsulates the creation of a tree hash from streamed chunks of data

  Aws\Common\Hash\TreeHash implements Aws\Common\Hash\ChunkHashInterface

Namespace: Aws\Common\Hash
Located at Aws/Common/Hash/TreeHash.php

## 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 by `hash_algos()`

#### Returns

``Aws\Common\Hash\TreeHash``
# `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 by `hash_algos()`

#### Returns

``Aws\Common\Hash\TreeHash``
# `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 by `hash_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 by `hash_algos()`

#### Returns

``Aws\Common\Hash\TreeHash``

#### Implementation of

`Aws\Common\Hash\ChunkHashInterface::__construct()`
# `public `Aws\Common\Hash\TreeHash``
`addData( string $data )`

Add a chunk of data to be hashed

#### Parameters

$data
  `string`
  $data Data to be hashed

#### Returns

``Aws\Common\Hash\TreeHash``

#### 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

`Aws\Common\Hash\ChunkHashInterface::addData()`
# `public `Aws\Common\Hash\TreeHash``
`addChecksum( string $checksum, boolean $inBinaryForm = false )`

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

``Aws\Common\Hash\TreeHash``

#### Throws

``Aws\Common\Exception\LogicException``
if the root tree hash is already calculated
# `public string`
`getHash( boolean $returnBinaryForm = false )`

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

`Aws\Common\Hash\ChunkHashInterface::getHash()`
# `public array`
`getChecksums( )`

#### Returns

`array`
Array of raw checksums composing the tree hash

### Magic methods summary

## Constants summary

### Constants inherited from Aws\Common\Hash\ChunkHashInterface

`DEFAULT_ALGORITHM`

## 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