ion-hash-python¶
API documentation for the ion-hash-python GitHub repository.
ionhash.hasher module¶
Adds an ion_hash() method to all simpleion value classes, and provides readers/writers that hash Ion values according to the Ion Hash Specification.
-
class
ionhash.hasher.
HashEvent
(name, value)¶ Bases:
amazon.ion.util.Enum
Events that may be pushed into a hash_reader or hash_writer coroutine, in addition to those allowed by the wrapped reader/writer.
- Attributes:
- DIGEST: produces bytes that represents the hash of the Ion values read/written
-
DIGEST
= <HashEvent.DIGEST: 0>¶
-
class
ionhash.hasher.
IonHasher
¶ Bases:
abc.ABC
Abstract class declaring the hashing methods that must be implemented in order to support a hash function for use by hash_reader or hash_writer.
-
digest
()¶ Returns a digest of the accumulated bytes passed to update, and resets the IonHasher to its initial state.
-
update
(_bytes)¶ Updates the hash function with the specified _bytes.
-
-
ionhash.hasher.
hashlib_hash_function_provider
(algorithm)¶ A hash function provider based on hashlib.
-
<simpleion_class>.ion_hash(algorithm=None, hash_function_provider=None)
Given an algorithm or hash_function_provider, computes the Ion hash of this value.
- Args:
- algorithm:
- A string corresponding to the name of a hash algorithm supported by the hashlib module.
- hash_function_provider:
A function that returns a new
IonHasher
instance when called.Note that multiple
IonHasher
instances may be required to hash a single value (depending on the type of the Ion value).
- Returns:
- bytes that represent the Ion hash of this value for the specified algorithm or hash_function_provider.
-
ionhash.hasher.
hash_reader
(reader, hash_function_provider)¶ Provides a coroutine that wraps an ion-python reader and adds Ion Hash functionality.
The given coroutine yields bytes when given
HashEvent.DIGEST
. Otherwise, the couroutine’s behavior matches that of the wrapped reader.- Notes:
- The coroutine translates any amazon.ion.reader.SKIP_EVENTs into a series of amazon.ion.reader.NEXT_EVENTs in order to ensure that the hash correctly includes any subsequent or nested values.
- Args:
- reader(couroutine):
- An ion-python reader coroutine.
- hash_function_provider(function):
A function that returns a new
IonHasher
instance when called.Note that multiple
IonHasher
instances may be required to hash a single value (depending on the type of the Ion value).
- Yields:
- bytes:
- The result of hashing.
- other values:
- As defined by the provided reader coroutine.
-
ionhash.hasher.
hash_writer
(writer, hash_function_provider)¶ Provides a coroutine that wraps an ion-python writer and adds Ion Hash functionality.
The given coroutine yields bytes when given
HashEvent.DIGEST
. Otherwise, the couroutine’s behavior matches that of the wrapped writer.- Args:
- writer(coroutine):
- An ion-python writer coroutine.
- hash_function_provider(function):
A function that returns a new
IonHasher
instance when called.Note that multiple
IonHasher
instances may be required to hash a single value (depending on the type of the Ion value).
- Yields:
- bytes:
- The result of hashing.
- other values:
- As defined by the provided writer coroutine.