(streams command.Streams, keyPath string, options keyLoadOptions)
| 44 | } |
| 45 | |
| 46 | func 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 | |
| 73 | func getPrivKeyBytesFromPath(keyPath string) ([]byte, error) { |
| 74 | if runtime.GOOS != "windows" { |
no test coverage detected
searching dependent graphs…