-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
payload
and add-signature
commands.
Fixes #205.
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/flynn/go-docopt" | ||
"github.com/theupdateframework/go-tuf" | ||
"github.com/theupdateframework/go-tuf/data" | ||
) | ||
|
||
func init() { | ||
register("add-signature", cmdAddSignature, ` | ||
usage: tuf add-signature <role> --key-id <key_id> --signature <sig_file> | ||
Adds a signature (as hex-encoded bytes) generated by an offline tool to the given role. | ||
If the signature does not verify, it will not be added. | ||
`) | ||
} | ||
|
||
func cmdAddSignature(args *docopt.Args, repo *tuf.Repo) error { | ||
role := args.String["<role>"] | ||
keyID := args.String["<key_id>"] | ||
|
||
f := args.String["<sig_file>"] | ||
sigBytes, err := os.ReadFile(f) | ||
if err != nil { | ||
return err | ||
} | ||
sigData := data.HexBytes(sigBytes) | ||
|
||
sig := data.Signature{ | ||
KeyID: keyID, | ||
Signature: sigData, | ||
} | ||
return repo.AddOrUpdateSignature(role, sig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/flynn/go-docopt" | ||
"github.com/theupdateframework/go-tuf" | ||
) | ||
|
||
func init() { | ||
register("payload", cmdPayload, ` | ||
usage: tuf payload <role> | ||
Output a role's metadata in a ready-to-sign format. | ||
The output is canonicalized. | ||
`) | ||
} | ||
|
||
func cmdPayload(args *docopt.Args, repo *tuf.Repo) error { | ||
p, err := repo.Payload(args.String["<role>"]) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(p)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters