Constructor
new SalmonIntegrity(integrity, key, chunkSize, provider, hashSize)
Instantiate an object to be used for applying and verifying hash signatures for each of the data chunks.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
integrity |
boolean | True to enable integrity checks. | |
key |
Uint8Array | The key to use for hashing. | |
chunkSize |
number | null | null | The chunk size. Use 0 to enable integrity on the whole file (1 chunk). Use a positive number to specify integrity chunks. |
provider |
IHashProvider | Hash implementation provider. | |
hashSize |
number | 0 | The hash size. |
Throws:
-
IntegrityException When integrity is comprimised
-
SalmonSecurityException When security has failed
Classes
Members
(static) DEFAULT_CHUNK_SIZE
Default chunk size for integrity.
(static) MAX_CHUNK_SIZE
Maximum chunk size for data integrity.
Methods
(async) generateHashes(buffer, includeHeaderData) → {Promise.<(Array.<Uint8Array>|null)>}
Generate a hash signatures for each data chunk.
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Uint8Array | The buffer containing the data chunks. |
includeHeaderData |
boolean | Include the header data in the first chunk. |
Throws:
IntegrityException Thrown if the data are corrupt or tampered with.
Returns:
The hash signatures.
- Type
- Promise.<(Array.<Uint8Array>|null)>
getChunkSize() → {number}
Get the chunk size.
Returns:
The chunk size.
- Type
- number
getHashDataLength(count, hashOffset) → {number}
Return the number of bytes that all hash signatures occupy for each chunk size
Parameters:
Name | Type | Description |
---|---|---|
count |
number | Actual length of the real data int the base stream including header and hash signatures. |
hashOffset |
number | The hash key length |
Returns:
The number of bytes all hash signatures occupy
- Type
- number
getHashes(buffer) → {Array.<Uint8Array>|null}
Get the hashes for each data chunk.
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Uint8Array | The buffer that contains the data chunks. |
Returns:
The hash signatures.
- Type
- Array.<Uint8Array> | null
getKey() → {Uint8Array}
Get the hash key.
Returns:
The hash key.
- Type
- Uint8Array
useIntegrity() → {boolean}
Get the integrity enabled option.
Returns:
True if integrity is enabled.
- Type
- boolean
(async) verifyHashes(hashes, buffer, includeHeaderData)
Verify the buffer chunks against the hash signatures.
Parameters:
Name | Type | Description |
---|---|---|
hashes |
Array.<Uint8Array> | The hashes to verify. |
buffer |
number | The buffer that contains the chunks to verify the hashes. |
includeHeaderData |
boolean | null |
Throws:
IntegrityException Thrown if the data are corrupt or tampered with.
(async, static) calculateHash(provider, buffer, offset, count, key, includeData) → {Promise.<Uint8Array>}
Calculate hash of the data provided.
Parameters:
Name | Type | Description |
---|---|---|
provider |
IHashProvider | Hash implementation provider. |
buffer |
Uint8Array | Data to calculate the hash. |
offset |
number | Offset of the buffer that the hashing calculation will start from |
count |
number | Length of the buffer that will be used to calculate the hash. |
key |
Uint8Array | Key that will be used |
includeData |
Uint8Array | null | Additional data to be included in the calculation. |
Throws:
IntegrityException Thrown if the data are corrupt or tampered with.
Returns:
The hash.
- Type
- Promise.<Uint8Array>
(static) getTotalHashDataLength(length, chunkSize, hashOffset, hashLength) → {number}
Get the total number of bytes for all hash signatures for data of a specific length.
Parameters:
Name | Type | Description |
---|---|---|
length |
number | The length of the data. |
chunkSize |
number | The byte size of the stream chunk that will be used to calculate the hash. The length should be fixed value except for the last chunk which might be lesser since we don't use padding |
hashOffset |
number | The hash key length that will be used as an offset. |
hashLength |
number | The hash length. |
Returns:
The total number of bytes for all hash signatures.
- Type
- number