...

Source file src/github.com/theupdateframework/go-tuf/client/testdata/tools/gen-keys.go

Documentation: github.com/theupdateframework/go-tuf/client/testdata/tools

     1  // This helper files generates a bunch of ed25519 keys to be used by the test
     2  // runners. This is done such that the signatures stay stable when the metadata
     3  // is regenerated.
     4  
     5  package main
     6  
     7  import (
     8  	"encoding/json"
     9  	"fmt"
    10  	"os"
    11  	"time"
    12  
    13  	"github.com/theupdateframework/go-tuf/data"
    14  )
    15  
    16  var expirationDate = time.Date(2100, time.January, 1, 0, 0, 0, 0, time.UTC)
    17  
    18  func main() {
    19  	rolenames := []string{
    20  		"root",
    21  		"snapshot",
    22  		"targets",
    23  		"timestamp",
    24  	}
    25  
    26  	roles := make(map[string][][]*data.PrivateKey)
    27  
    28  	for _, name := range rolenames {
    29  		keys := [][]*data.PrivateKey{}
    30  
    31  		for i := 0; i < 2; i++ {
    32  			signer, err := keys.GenerateEd25519Key()
    33  			assertNoError(err)
    34  			keys = append(keys, []*data.PrivateKey{signer})
    35  		}
    36  
    37  		roles[name] = keys
    38  	}
    39  
    40  	s, err := json.MarshalIndent(&roles, "", "    ")
    41  	assertNoError(err)
    42  
    43  	os.WriteFile("keys.json", []byte(s), 0644)
    44  }
    45  
    46  func assertNoError(err error) {
    47  	if err != nil {
    48  		panic(fmt.Sprintf("assertion failed: %s", err))
    49  	}
    50  }
    51  

View as plain text