Skip to content

Commit

Permalink
fix: add-signature to read from stdin
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Brough <[email protected]>
  • Loading branch information
ChevronTango committed Jul 30, 2023
1 parent 4e4f7f3 commit 66510c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ Typically, `path` will be a file containing the output of `tuf payload`.

See also `tuf add-signatures`.

#### `tuf add-signatures --signatures <sig_file> <metadata>`

#### `tuf add-signatures [--signatures <sig_file>] <metadata>`

Adds signatures (the output of `tuf sign-payload`) to the given role metadata file.

If the signature does not verify, it will not be added.
If the signature does not verify, it will not be added. Signature can be a json file
or passed in via `stdin`.

#### `tuf status --valid-at <date> <role>`

Expand Down
23 changes: 18 additions & 5 deletions cmd/tuf/add_signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@ import (

func init() {
register("add-signatures", cmdAddSignature, `
usage: tuf add-signatures --signatures <sig_file> <metadata>
usage: tuf add-signatures [--signatures <sig_file>] <metadata>
Adds signatures (the output of "sign-payload") to the given role metadata file.
If the signature does not verify, it will not be added.
Options:
--signatures=<sig_file> The path to the file containing the signatures to add. If not present, the contents are read from stdin
`)
}

func cmdAddSignature(args *docopt.Args, repo *tuf.Repo) error {
roleFilename := args.String["<metadata>"]

f := args.String["<sig_file>"]
sigBytes, err := os.ReadFile(f)
if err != nil {
return err
f := args.String["--signatures"]
var sigBytes []byte
var err error
if f != "" {
sigBytes, err = os.ReadFile(f)
if err != nil {
return err
}
} else {
var input string
_, err := fmt.Scan(&input)
if err != nil {
return err
}
sigBytes = []byte(input)
}
sigs := []data.Signature{}
if err = json.Unmarshal(sigBytes, &sigs); err != nil {
Expand Down

0 comments on commit 66510c8

Please sign in to comment.