-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull-foc-encryption.sh
More file actions
executable file
·96 lines (85 loc) · 3.36 KB
/
Copy pathpull-foc-encryption.sh
File metadata and controls
executable file
·96 lines (85 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
#
# pull-foc-encryption.sh — vendor the pinned foc-encryption reference
# implementation and (re)generate + verify the FEE cross-implementation
# fixtures against it.
#
# The reference is github.com/Kubuxu/foc-encryption-demo, packages/foc-encryption,
# pinned to a fixed commit (see REF_SHA below) for reproducibility. The vendored
# source is written under ts/vendor/ (gitignored) and never committed; only this
# script, the ts/ driver, and the generated testdata/ fixtures are.
#
# Usage:
# ./pull-foc-encryption.sh # generate the TS fixture + verify all
# ./pull-foc-encryption.sh verify # verify committed fixtures only
# ./pull-foc-encryption.sh generate # (re)generate the TS fixture only
#
# Requires: bun (https://bun.sh) and either git or curl for the source pull.
set -euo pipefail
REF_REPO="https://github.com/Kubuxu/foc-encryption-demo"
REF_SHA="158571aed08239d6b08b41d390d8ff9d915fd145"
REF_FETCH="refs/heads/master" # ref that reaches REF_SHA
PKG_SUBDIR="packages/foc-encryption"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TS_DIR="$SCRIPT_DIR/ts"
VENDOR="$TS_DIR/vendor/foc-encryption"
# Source files fetched by the raw fallback (the git path copies the whole
# package). This list is fixed for the pinned commit.
SRC_FILES=(
src/index.ts src/envelope.ts src/blob.ts src/crypto.ts src/kdf.ts
src/key-utils.ts src/types.ts src/errors.ts
src/cose/decode.ts src/cose/encode.ts src/cose/headers.ts
src/cose/structures.ts src/cose/tags.ts
src/schemes/scheme.ts src/schemes/aes-256-gcm.ts src/schemes/chunked-aes-256-gcm.ts
)
log() { printf '>> %s\n' "$*"; }
# fetch_via_git clones and checks out the pinned SHA, then copies the package
# into the vendor dir. Returns non-zero if git is unavailable or the clone fails
# (e.g. behind a proxy that blocks git), so the caller can fall back to raw.
fetch_via_git() {
command -v git >/dev/null 2>&1 || return 1
local tmp
tmp="$(mktemp -d)"
if git clone --quiet "$REF_REPO" "$tmp" 2>/dev/null &&
git -C "$tmp" fetch --quiet origin "$REF_FETCH" 2>/dev/null &&
git -C "$tmp" checkout --quiet "$REF_SHA" 2>/dev/null; then
rm -rf "$VENDOR"
mkdir -p "$VENDOR"
cp -R "$tmp/$PKG_SUBDIR/." "$VENDOR/"
rm -rf "$tmp"
return 0
fi
rm -rf "$tmp"
return 1
}
# fetch_via_raw pulls the individual pinned source files over HTTPS. This works
# in environments whose egress allows raw.githubusercontent.com but not git.
fetch_via_raw() {
command -v curl >/dev/null 2>&1 || {
echo "error: need git or curl to fetch the reference source" >&2
exit 1
}
local base="https://raw.githubusercontent.com/Kubuxu/foc-encryption-demo/$REF_SHA/$PKG_SUBDIR"
rm -rf "$VENDOR"
local f
for f in "${SRC_FILES[@]}"; do
mkdir -p "$VENDOR/$(dirname "$f")"
curl -fsSL "$base/$f" -o "$VENDOR/$f"
done
}
log "vendoring foc-encryption @ ${REF_SHA:0:12}"
if fetch_via_git; then
log "source obtained via git clone"
else
log "git clone unavailable; falling back to raw file fetch"
fetch_via_raw
log "source obtained via raw.githubusercontent.com"
fi
command -v bun >/dev/null 2>&1 || {
echo "error: bun is required to run the TS reference (https://bun.sh)" >&2
exit 1
}
log "installing harness dependencies (cborg)"
(cd "$TS_DIR" && bun install --silent)
log "running the foc-encryption driver"
(cd "$TS_DIR" && bun driver.ts "${1:-all}")