interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / cbor / test / gen / regen.sh

41 lines · 2197 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Regenerates the oracle-made vector files of om/cbor into OUTDIR (default: test/vectors).
4# Usage: sh om/cbor/test/gen/regen.sh GO [OUTDIR]
5# GO is a Go toolchain >= 1.26.5 (the go directive of tailscale.com v1.102.0). The oracle imports
6# tailscale.com/tka v1.102.0 and github.com/fxamacker/cbor/v2 v2.9.0 (go.sum pins both); the first
7# run downloads them through the Go module proxy. Test referee only: nothing here is shipped.
8set -eu
9go=${1:?usage: regen.sh GO [OUTDIR]}
10here=$(cd "$(dirname "$0")" && pwd)
11out=${2:-$(dirname "$here")/vectors}
12bin=$(mktemp -d)
13trap 'rm -rf "$bin"' EXIT
14(cd "$here/oracle" && "$go" build -o "$bin/oracle" .)
15gov=$("$go" env GOVERSION)
16o="$bin/oracle"
17
18hdr() { # hdr FILE COMMAND DESCRIPTION
19 {
20 echo "# om/cbor vectors: $3"
21 echo "# Generated by \`oracle $2\` (om/cbor/test/gen/oracle, $gov) from tailscale.com v1.102.0"
22 echo "# (tka types and Serialize/Unserialize) and github.com/fxamacker/cbor/v2 v2.9.0."
23 echo "# Regenerate: sh om/cbor/test/gen/regen.sh GO. Same seed, same bytes."
24 } > "$1"
25}
26
27hdr "$out/tka-structs.txt" "gen 1 1200" "AUM, NodeKeySignature and State structures."
28echo "# Line: TYPE HEX HASH K1. HEX = tka Serialize (CTAP2); HASH = AUM.Hash() for aum, BLAKE2s-256(HEX) otherwise; K1 = major:argument at key 1." >> "$out/tka-structs.txt"
29"$o" gen 1 1200 >> "$out/tka-structs.txt"
30
31hdr "$out/hostile.txt" "hostile" "hostile corpus, each case judged by tka's own Unserialize."
32echo "# Line: CLASS TARGET WF ACCEPT RESER HEX DESCRIPTION. WF = Wellformed code (0 = well-formed); ACCEPT = TARGET.Unserialize accepted; RESER = tka Serialize after decoding, or -." >> "$out/hostile.txt"
33"$o" hostile >> "$out/hostile.txt"
34
35hdr "$out/fuzz.txt" "fuzz 1 2000" "random mutations (bit flips, byte changes, cuts, inserts, deletes) of generated structures."
36echo "# Line: WF AUM NKS HEX. AUM/NKS = 1 when tka's AUM/NodeKeySignature Unserialize accepted the bytes." >> "$out/fuzz.txt"
37"$o" fuzz 1 2000 >> "$out/fuzz.txt"
38
39hdr "$out/utf8.txt" "utf8 1 2000" "single CBOR text strings; VALID from Go unicode/utf8.Valid."
40echo "# Line: VALID HEX." >> "$out/utf8.txt"
41"$o" utf8 1 2000 >> "$out/utf8.txt"