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

Function loadPrivKey

cmd/docker-trust/trust/key_load.go:46–71  ·  view source on GitHub ↗
(streams command.Streams, keyPath string, options keyLoadOptions)

Source from the content-addressed store, hash-verified

44}
45
46func loadPrivKey(streams command.Streams, keyPath string, options keyLoadOptions) error {
47 // validate the key name if provided
48 if options.keyName != "" && !validKeyName(options.keyName) {
49 return fmt.Errorf("key name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", options.keyName)
50 }
51 trustDir := trust.GetTrustDirectory()
52 keyFileStore, err := storage.NewPrivateKeyFileStorage(trustDir, notary.KeyExtension)
53 if err != nil {
54 return err
55 }
56 privKeyImporters := []trustmanager.Importer{keyFileStore}
57
58 _, _ = fmt.Fprintf(streams.Out(), "Loading key from \"%s\"...\n", keyPath)
59
60 // Always use a fresh passphrase retriever for each import
61 passRet := trust.GetPassphraseRetriever(streams.In(), streams.Out())
62 keyBytes, err := getPrivKeyBytesFromPath(keyPath)
63 if err != nil {
64 return fmt.Errorf("refusing to load key from %s: %w", keyPath, err)
65 }
66 if err := loadPrivKeyBytesToStore(keyBytes, privKeyImporters, keyPath, options.keyName, passRet); err != nil {
67 return fmt.Errorf("error importing key from %s: %w", keyPath, err)
68 }
69 _, _ = fmt.Fprintln(streams.Out(), "Successfully imported key from", keyPath)
70 return nil
71}
72
73func getPrivKeyBytesFromPath(keyPath string) ([]byte, error) {
74 if runtime.GOOS != "windows" {

Callers 1

newKeyLoadCommandFunction · 0.85

Calls 4

getPrivKeyBytesFromPathFunction · 0.85
loadPrivKeyBytesToStoreFunction · 0.85
OutMethod · 0.65
InMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…