aboutsummaryrefslogtreecommitdiff
path: root/test/TestSupport.mc
diff options
context:
space:
mode:
authorcirakg <cirakg@cirakg.xyz>2026-10-18 23:44:18 +0200
committercirakg <cirakg@cirakg.xyz>2026-10-18 23:44:18 +0200
commit93aa7e3aa291f3328cf34a5a2f86172f41d0affd (patch)
treeac44438e7340fde609ad6458e31e122612cf35d1 /test/TestSupport.mc
parent5646ae7f40dc53c9ebed0b3b6e907cc85fcd5993 (diff)
test: add cross-checked crypto/OTP vectors, unit tests and stricter screenshots
- gen_vectors.py: RFC/FIPS/NIST vectors recomputed with Python's stdlib (openssl for AES) before use, plus seeded cases around SHA padding boundaries, 2038 and 2100; generates test/data/Vectors.mc. - 31 Monkey C tests (hashes, HMAC, PBKDF2, HKDF, AES, sealed records incl. every-byte tamper detection, Base32 errors, 100 OTP and 12 Steam vectors, clock, jobs) and a benchmark; pass on all four test devices. - Screenshot tolerance 0.01 %: one changed character no longer passes. - Golden images updated for version 0.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test/TestSupport.mc')
-rw-r--r--test/TestSupport.mc53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/TestSupport.mc b/test/TestSupport.mc
new file mode 100644
index 0000000..f6fa4b7
--- /dev/null
+++ b/test/TestSupport.mc
@@ -0,0 +1,53 @@
+// Author: cirakg & claude ai
+// Summary: Small helpers shared by the Monkey C unit tests (reading vector rows, reporting mismatches).
+
+import Toybox.Lang;
+import Toybox.Test;
+
+(:test)
+module TestSupport {
+
+ // One row of a TestVectors table.
+ function row(table as Array, index as Number) as Array {
+ return table[index] as Array;
+ }
+
+ function str(r as Array, column as Number) as String {
+ return r[column] as String;
+ }
+
+ function bytes(r as Array, column as Number) as ByteArray {
+ return Bytes.fromHex(r[column] as String);
+ }
+
+ function num(r as Array, column as Number) as Number {
+ return r[column] as Number;
+ }
+
+ // Numbers above 2^31 are stored as Long literals in the tables.
+ function long(r as Array, column as Number) as Long {
+ return (r[column] as Number or Long).toLong();
+ }
+
+ function alg(r as Array, column as Number) as Hashes.Algorithm {
+ return r[column] as Hashes.Algorithm;
+ }
+
+ // Compare bytes; log both sides on mismatch. Returns true when equal.
+ function sameBytes(logger as Test.Logger, what as String, actual as ByteArray, expected as ByteArray) as Boolean {
+ if (Bytes.equal(actual, expected)) {
+ return true;
+ }
+ logger.error(what + ": got " + Bytes.toHex(actual) + ", expected " + Bytes.toHex(expected));
+ return false;
+ }
+
+ // Compare strings; log both sides on mismatch.
+ function sameString(logger as Test.Logger, what as String, actual as String, expected as String) as Boolean {
+ if (actual.equals(expected)) {
+ return true;
+ }
+ logger.error(what + ": got '" + actual + "', expected '" + expected + "'");
+ return false;
+ }
+}