|
1 | 1 | package nl.sanderdijkhuis.noise |
2 | 2 |
|
3 | | -data class CipherState(val cryptography: Cryptography, val k: CipherKey? = null, val n: Nonce = Nonce.zero()) { |
| 3 | +data class CipherState(val cryptography: Cryptography, val key: CipherKey? = null, val nonce: Nonce = Nonce.zero) { |
4 | 4 |
|
5 | 5 | fun encryptWithAssociatedData(associatedData: AssociatedData, plaintext: Plaintext) = |
6 | | - k?.let { |
7 | | - println("Encrypting $k $n $associatedData $plaintext") |
8 | | - State(copy(n = n.increment()), cryptography.encrypt(it, n, associatedData, plaintext)) |
| 6 | + key?.let { |
| 7 | + println("Encrypting $key $nonce $associatedData $plaintext") |
| 8 | + State(copy(nonce = nonce.increment()), cryptography.encrypt(it, nonce, associatedData, plaintext)) |
9 | 9 | } ?: let { |
10 | | - println("Returning plaintext $plaintext $n") |
| 10 | + println("Returning plaintext $plaintext $nonce") |
11 | 11 | State(this, plaintext.ciphertext) |
12 | 12 | } |
13 | 13 |
|
14 | | - fun decryptWithAssociatedData( |
15 | | - associatedData: AssociatedData, |
16 | | - ciphertext: Ciphertext |
17 | | - ): State<CipherState, Plaintext>? = let { |
18 | | - println("Decrypting $k $n $associatedData $ciphertext") |
19 | | - if (k == null) |
| 14 | + fun decryptWithAssociatedData(data: AssociatedData, ciphertext: Ciphertext): State<CipherState, Plaintext>? = let { |
| 15 | + println("Decrypting $key $nonce $data $ciphertext") |
| 16 | + if (key == null) |
20 | 17 | State(this, ciphertext.plaintext) |
21 | 18 | else |
22 | | - cryptography.decrypt(k, n, associatedData, ciphertext)?.let { |
23 | | - State(copy(n = n.increment()), it) |
| 19 | + cryptography.decrypt(key, nonce, data, ciphertext)?.let { |
| 20 | + State(copy(nonce = nonce.increment()), it) |
24 | 21 | } |
25 | 22 | } |
26 | | - |
27 | | -// fun rekey() = k?.rekey() |
28 | 23 | } |
0 commit comments