MCPcopy Create free account
hub / github.com/docker/cli / validateAndGenerateKey

Function validateAndGenerateKey

cmd/docker-trust/trust/key_generate.go:76–102  ·  view source on GitHub ↗
(streams command.Streams, keyName string, workingDir string)

Source from the content-addressed store, hash-verified

74}
75
76func validateAndGenerateKey(streams command.Streams, keyName string, workingDir string) error {
77 freshPassRetGetter := func() notary.PassRetriever { return trust.GetPassphraseRetriever(streams.In(), streams.Out()) }
78 if err := validateKeyArgs(keyName, workingDir); err != nil {
79 return err
80 }
81 _, _ = fmt.Fprintf(streams.Out(), "Generating key for %s...\n", keyName)
82 // Automatically load the private key to local storage for use
83 privKeyFileStore, err := trustmanager.NewKeyFileStore(trust.GetTrustDirectory(), freshPassRetGetter())
84 if err != nil {
85 return err
86 }
87
88 pubPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore)
89 if err != nil {
90 _, _ = fmt.Fprint(streams.Out(), err)
91 return fmt.Errorf("failed to generate key for %s: %w", keyName, err)
92 }
93
94 // Output the public key to a file in the CWD or specified dir
95 writtenPubFile, err := writePubKeyPEMToDir(pubPEM, keyName, workingDir)
96 if err != nil {
97 return err
98 }
99 _, _ = fmt.Fprintln(streams.Out(), "Successfully generated and loaded private key. Corresponding public key available:", writtenPubFile)
100
101 return nil
102}
103
104func generateKeyAndOutputPubPEM(keyName string, privKeyStore trustmanager.KeyStore) (pem.Block, error) {
105 privKey, err := tufutils.GenerateKey(data.ECDSAKey)

Callers 1

Calls 5

validateKeyArgsFunction · 0.85
writePubKeyPEMToDirFunction · 0.85
InMethod · 0.65
OutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…