Skip to content

Commit f7c6302

Browse files
committed
Introduced newDeriveKeyHasher(Hasher => Unit)
1 parent 1ae5ddc commit f7c6302

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
All notable changes to this project will be documented in this file.
44

55
## [unreleased]
6+
- Introduced `newDeriveKeyHasher(Hasher => Unit)`.
67
- Introduced `update(Short)`, `update(Int)` and `update(Long)`.
78

89
## [2.2.0] - 2021-01-05

shared/src/main/scala/ky/korins/blake3/Blake3.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,21 @@ object Blake3 {
3333
}
3434

3535
/**
36-
* A new hasher with derive key that might be any array of bytes
36+
* A new hasher with derive key that should be initalized via callback
3737
*/
38-
def newDeriveKeyHasher(context: Array[Byte]): Hasher = {
39-
val contextKey = new HasherImpl(IV, DERIVE_KEY_CONTEXT)
40-
.update(context)
41-
.done(KEY_LEN)
38+
def newDeriveKeyHasher(cb: Hasher => Unit): Hasher = {
39+
val contextKeyHasher = new HasherImpl(IV, DERIVE_KEY_CONTEXT)
40+
cb(contextKeyHasher)
41+
val contextKey = contextKeyHasher.done(KEY_LEN)
4242
new HasherImpl(wordsFromLittleEndianBytes(contextKey), DERIVE_KEY_MATERIAL)
4343
}
4444

45+
/**
46+
* A new hasher with derive key that might be any array of bytes
47+
*/
48+
def newDeriveKeyHasher(context: Array[Byte]): Hasher =
49+
newDeriveKeyHasher(_.update(context))
50+
4551
/**
4652
* A new hasher with derive key that might be any string
4753
*/

0 commit comments

Comments
 (0)