-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add META.sh file to extract data from META.json
This commit adds a basic script META.sh to query the META.json. If jq is present, it's used for the query. Otherwise, some basic fiddling with cat, grep, cut, and tr is used. This is used to conduct a bash-based KAT test in `make quickcheck`, rather then running the test scripts, which already require a Python setup. Signed-off-by: Hanno Becker <[email protected]>
- Loading branch information
1 parent
f5703c8
commit 6a49c8a
Showing
2 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
Check failure on line 1 in META.sh GitHub Actions / Linting (ubuntu-latest)Format error
|
||
|
||
# Helper script to query META.json | ||
# | ||
# Arguments | ||
# - Scheme to query: ML-KEM-512, ML-KEM-768, ML-KEM-1024 | ||
# - Field to query, e.g. "kat-sha256" | ||
# | ||
# Optional: | ||
# - Value to compare against | ||
|
||
META=META.json | ||
|
||
# Manual extraction of metadata with basic cmd line tools | ||
VAL=$(cat $META | | ||
grep "name\|\"$2\"" | | ||
grep $1 -A 1 | | ||
grep $2 | | ||
cut -d ":" -f 2 | | ||
tr -d '", ') | ||
|
||
# More robust extraction using jq | ||
if (which jq 2>&1 >/dev/null); then | ||
QUERY=".implementations | .[] | select(.name==\"$1\") | .\"$2\"" | ||
VAL_JQ=$(cat $META | jq "$QUERY" -r) | ||
|
||
if [[ $VAL_JQ != $VAL ]]; then | ||
echo "ERROR parsing metadata file $META" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
INPUT=$3 | ||
if [[ "$INPUT" != "" ]]; then | ||
if [[ "$INPUT" != "$VAL" ]]; then | ||
echo "$META $1 $2: FAIL ($VAL != $INPUT)" | ||
exit 1 | ||
else | ||
echo "$META $1 $2: OK" | ||
exit 0 | ||
fi | ||
else | ||
echo $VAL | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters