Add mintsturdyref

Formally a utility hidden in the syndicate/capabilities module.
This commit is contained in:
Emery Hemingway 2023-08-25 10:14:13 +01:00
parent fe7b0f469d
commit c08ed920b5
3 changed files with 49 additions and 1 deletions

View File

@ -10,6 +10,10 @@ Utility to communicate with sockets that send and receive lines of JSON using `<
Do not send messages immediately to the dataspace passed `json_socket_translator`, wait until it asserts `<connected @socketPath string>`.
## mintsturdyref
A utility for minting [Sturdyrefs](https://synit.org/book/operation/builtin/gatekeeper.html#sturdyrefs).
## msg
A utility that sends a message to `$SYNDICATE_SOCK` in the form `<ARGV0 ARG1 … ARGVn>`.

44
src/mintsturdyref.nim Normal file
View File

@ -0,0 +1,44 @@
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
from os import commandLineParams
import preserves, syndicate/capabilities
const usage = """
mintsturdyref OID < SECRET_KEY
Mint Sturdyrefs using a sixteen-byte secret key read from stdin using OIDs
passed as command-line parameters.
Example:
mintsturdyref '"syndicate"' < /dev/null
See:
https://synit.org/book/operation/builtin/gatekeeper.html#sturdyrefs
https://synit.org/book/glossary.html?highlight=oid#oid
"""
proc main =
var oids: seq[Preserve[void]]
for p in commandLineParams():
case p
of "-h", "--help", "?":
quit(usage)
else:
add(oids, parsePreserves p)
if oids.len == 0:
stderr.writeLine """using the "syndicate" OID"""
oids.add(toPreserve "syndicate")
var key: array[16, byte]
case readBytes(stdin, key, 0, 16)
of 16: discard
of 0: stderr.writeLine "using null key"
else: quit "expected sixteen bytes of key from stdin"
for oid in oids:
let sturdy = mint(key, oid)
doAssert validate(key, sturdy)
stdout.writeLine(sturdy)
main()

View File

@ -5,7 +5,7 @@ author = "Emery Hemingway"
description = "Utilites for Syndicated Actors and Synit"
license = "unlicense"
srcDir = "src"
bin = @["json_socket_translator", "json_translator", "msg", "net_mapper", "preserve_process_environment", "syndex_card", "syndump"]
bin = @["json_socket_translator", "json_translator", "mintsturdyref", "msg", "net_mapper", "preserve_process_environment", "syndex_card", "syndump"]
# Dependencies