Skip to content

Commit

Permalink
Test for incrementNonce() with data sourced from real run.
Browse files Browse the repository at this point in the history
  • Loading branch information
causalnet committed Jan 15, 2023
1 parent 4f6fe4a commit aae6be9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/keepassxc/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ private byte[] ramdomGenerateNonce() {
* @param nonce The nonce to be incremented.
* @return nonce "+1".
*/
private byte[] incrementNonce(byte[] nonce) {
static byte[] incrementNonce(byte[] nonce) {
var c = 1;
byte[] incrementedNonce = nonce.clone();

Expand Down
19 changes: 19 additions & 0 deletions src/test/java/org/keepassxc/ConnectionNonceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.keepassxc;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class ConnectionNonceTest {
@Test
void test() {
byte[] before = new byte[] {
-1, 89, 10, 82, -100, 105, -57, 47, 124, -69, -39, -20, 80, -2, 17, 81, -26, 38, -14, -68, -44, -58, 98, -91
};
byte[] expected = new byte[] {
0, 90, 10, 82, -100, 105, -57, 47, 124, -69, -39, -20, 80, -2, 17, 81, -26, 38, -14, -68, -44, -58, 98, -91
};
byte[] actual = Connection.incrementNonce(before);
assertArrayEquals(expected, actual);
}
}

0 comments on commit aae6be9

Please sign in to comment.