-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathverify_rust_fixture.py
More file actions
78 lines (63 loc) · 1.98 KB
/
Copy pathverify_rust_fixture.py
File metadata and controls
78 lines (63 loc) · 1.98 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
"""Verify a Rust-generated authentication fixture with the Python SDK.
Usage:
uv run python examples/python/rust_interop_examples/verify_rust_fixture.py
"""
from __future__ import annotations
import json
import subprocess
from pathlib import Path
from anp.authentication import verify_auth_header_signature, verify_http_message_signature
def _repo_root() -> Path:
return Path(__file__).resolve().parents[3]
def _rust_root() -> Path:
return _repo_root() / "rust"
def _run_fixture(*args: str) -> dict:
cargo = "cargo"
result = subprocess.run(
[cargo, "run", "--quiet", "--example", "interop_cli", "--", *args],
cwd=_rust_root(),
capture_output=True,
text=True,
check=True,
)
return json.loads(result.stdout)
def main() -> None:
http_fixture = _run_fixture(
"auth-fixture",
"--profile",
"e1",
"--scheme",
"http",
"--url",
"https://api.example.com/orders",
"--method",
"POST",
"--body",
'{"item":"book"}',
)
is_valid, message, metadata = verify_http_message_signature(
did_document=http_fixture["did_document"],
request_method=http_fixture["request_method"],
request_url=http_fixture["request_url"],
headers=http_fixture["headers"],
body=http_fixture["body"].encode("utf-8"),
)
print(f"Rust HTTP signature verified in Python: {is_valid} ({message})")
print(f"Verification metadata: {metadata}")
legacy_fixture = _run_fixture(
"auth-fixture",
"--profile",
"k1",
"--scheme",
"legacy",
"--service-domain",
"api.example.com",
)
is_valid, message = verify_auth_header_signature(
legacy_fixture["headers"]["Authorization"],
legacy_fixture["did_document"],
legacy_fixture["service_domain"],
)
print(f"Rust legacy auth header verified in Python: {is_valid} ({message})")
if __name__ == "__main__":
main()