initKeyId sets c.keyId. It checks, in this order, the --gpgkey flag, the GPGKEY env var, and in the default identity secret ring.
()
| 114 | // initKeyId sets c.keyId. It checks, in this order, the --gpgkey flag, the GPGKEY env var, |
| 115 | // and in the default identity secret ring. |
| 116 | func (c *initCmd) initKeyId() error { |
| 117 | if c.keyId != "" { |
| 118 | } else if k := os.Getenv("GPGKEY"); k != "" { |
| 119 | c.keyId = k |
| 120 | } else if k, err := jsonsign.KeyIdFromRing(c.secretRing); err == nil { |
| 121 | c.keyId = k |
| 122 | log.Printf("Re-using identity with keyId %q found in file %s", c.keyId, c.secretRing) |
| 123 | } else { |
| 124 | hint := "You can set --gpgkey=<pubid> or the GPGKEY env var to select which key ID to use.\n" |
| 125 | return fmt.Errorf("No suitable gpg key was found in %v: %v.\n%v", c.secretRing, err, hint) |
| 126 | } |
| 127 | c.keyId = strings.TrimPrefix( |
| 128 | strings.ReplaceAll(c.keyId, " ", ""), |
| 129 | "0x", |
| 130 | ) |
| 131 | return nil |
| 132 | } |
| 133 | |
| 134 | func (c *initCmd) getPublicKeyArmored() ([]byte, error) { |
| 135 | entity, err := jsonsign.EntityFromSecring(c.keyId, c.secretRing) |
no test coverage detected