fix(battle-node): clarify NodeCrypto.GenerateKey contract + add fixed-vector regression test

Replace inaccurate GenerateKey docstring (it claimed to port Cryptographer.generateKeyString
directly but the input shape differs: server uses one hex digit per call, client uses
Random.Next(0,65535) per call). New doc is honest about the difference and explains why
it's safe. Add EncryptForNode_FixedVector_ProducesStableOutput: a pinned AES-CBC vector
that catches encoding/IV/padding regressions that would slip past the roundtrip test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-31 21:31:22 -04:00
parent 0a2eddd920
commit a786599416
2 changed files with 26 additions and 2 deletions

View File

@@ -41,4 +41,18 @@ public class NodeCryptoTests
{
Assert.Throws<ArgumentException>(() => NodeCrypto.DecryptForNode("tooshort"));
}
[Test]
public void EncryptForNode_FixedVector_ProducesStableOutput()
{
// Pinned wire-format regression: any change to encoding/padding/IV derivation
// that drifts in both directions would still pass the roundtrip test but break
// this hardcoded vector — and break interop with the real client.
const string plaintext = "hello, node!";
const string key = "01234567890123456789012345678901";
const string expected = "012345678901234567890123456789015mEezM5MgR7UUEkmx5OzPQ==";
Assert.That(NodeCrypto.EncryptForNode(plaintext, key), Is.EqualTo(expected));
Assert.That(NodeCrypto.DecryptForNode(expected), Is.EqualTo(plaintext));
}
}