Created
October 27, 2022 20:04
-
-
Save kommendorkapten/d78b84f74c333baaf4beaff7ab4ed09c to your computer and use it in GitHub Desktop.
JSON generator
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
// module tufprototest | |
// | |
// go 1.19 | |
// | |
// replace github.com/sigstore => /Users/kommendorkapten/git/tuf-protos/gen/pb-go/github.com/sigstore/ | |
// | |
// require ( | |
// github.com/sigstore v0.0.0-00010101000000-000000000000 // indirect | |
// google.golang.org/protobuf v1.28.1 // indirect | |
// ) | |
package main | |
import ( | |
"fmt" | |
tuf "github.com/sigstore/proto/tuf/v1" | |
timestamppb "google.golang.org/protobuf/types/known/timestamppb" | |
"google.golang.org/protobuf/encoding/protojson" | |
) | |
func intp(i int32) *int32{ | |
return &i | |
} | |
var meta = map[string]*tuf.MetaFileInfo{ | |
"kommander.txt": &tuf.MetaFileInfo{ | |
Version: 1, | |
Length: intp(0), | |
}, | |
} | |
var m = tuf.SnapshotTimestampRole{ | |
XType: "timestamp", | |
SpecVersion: "1.0.31", | |
Version: 1, | |
Expires: timestamppb.Now(), | |
Meta: meta, | |
} | |
var keys = map[string]*tuf.Key{ | |
"coffee": &tuf.Key{ | |
Keytype: "ed25519", | |
Scheme: "ed25519", | |
Keyval: &tuf.Public{ | |
Public: "68ead6e54a43f8f36f9717b10669d1ef0ebb38cee6b05317669341309f1069cb", | |
}, | |
}, | |
} | |
var roles = map[string]*tuf.Role{ | |
"root": &tuf.Role{ | |
Keyids: []string{"coffee"}, | |
Threshold: 1, | |
}, | |
} | |
var r = tuf.RootRole{ | |
XType: "root", | |
SpecVersion: "1.0.31", | |
ConsistentSnapshot: false, | |
Version: 1, | |
Expires: timestamppb.Now(), | |
Keys: keys, | |
Roles: roles, | |
} | |
func main() { | |
printMeta() | |
} | |
func printMeta() { | |
opt := protojson.MarshalOptions{UseProtoNames: true} | |
raw, err := opt.Marshal(&m) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println(string(raw)) | |
if raw, err = opt.Marshal(&r); err != nil { | |
panic(err) | |
} | |
fmt.Println(string(raw)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment