Skip to content

Commit 3cbc800

Browse files
committed
Update pipeline_gen_stfl_keys.py and pipeline for key check.
1 parent 4439b2e commit 3cbc800

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

.github/workflows/cache_xmss_and_xmssmt_keys.yml

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,8 @@ jobs:
6666
- name: Check if all keys are generated
6767
id: check-complete
6868
run: |
69-
# Use the Python function to check if all expensive keys are generated
70-
python -c "
71-
from pathlib import Path
72-
from scripts.pipeline_gen_stfl_keys import check_generated_all_keys
73-
import sys
74-
75-
out_dir = Path('${KEY_DIR}')
76-
if check_generated_all_keys(out_dir):
77-
print('All keys generated!')
78-
print('complete=true')
79-
sys.exit(0)
80-
else:
81-
print('Still missing some keys')
82-
print('complete=false')
83-
sys.exit(0)
84-
" | tee /tmp/check_output.txt
85-
86-
# Extract the complete status from output
87-
if grep -q "complete=true" /tmp/check_output.txt; then
69+
# Use the --check_keys_dir flag to verify all keys are present
70+
if python scripts/pipeline_gen_stfl_keys.py "${KEY_DIR}" --check_keys_dir; then
8871
echo "complete=true" >> $GITHUB_OUTPUT
8972
else
9073
echo "complete=false" >> $GITHUB_OUTPUT

scripts/pipeline_gen_stfl_keys.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,32 @@ def main(argv: Iterable[str] | None = None) -> int:
184184
"Defaults to $KEY_DIR if set, otherwise data/xmss_xmssmt_keys."
185185
),
186186
)
187+
parser.add_argument(
188+
"--check_keys_dir",
189+
action="store_true",
190+
help=(
191+
"If set, do not generate keys; only check whether all required "
192+
"XMSS/XMSSMT keys exist in the output directory. Returns 0 if all "
193+
"keys are present, 1 if any are missing."
194+
),
195+
)
187196
args = parser.parse_args(list(argv) if argv is not None else None)
188197

189198
out_dir = _resolve_out_dir(args.key_dir)
190-
stats = generate_keys(out_dir)
191-
192-
# For now we always return 0 to keep behavior similar to the inline script,
193-
# which only printed errors but did not cause the job to fail.
194-
if stats["missing"]:
195-
# If you later want to fail the pipeline, change this to return 1.
196-
pass
197199

200+
if args.check_keys_dir:
201+
# Only check whether all required keys are present; do not generate.
202+
all_present = check_generated_all_keys(out_dir)
203+
if all_present:
204+
logger.debug("All required XMSS/XMSSMT keys are present in %s", out_dir)
205+
return 0
206+
else:
207+
logger.debug("Some required XMSS/XMSSMT keys are missing in %s", out_dir)
208+
return 1
209+
210+
_ = generate_keys(out_dir)
198211
return 0
199212

200213

201-
if __name__ == "__main__": # pragma: no cover - thin CLI wrapper
214+
if __name__ == "__main__":
202215
main()

0 commit comments

Comments
 (0)