MCPcopy
hub / github.com/perkeep/perkeep / initKeyId

Method initKeyId

cmd/pk-put/init.go:116–132  ·  view source on GitHub ↗

initKeyId sets c.keyId. It checks, in this order, the --gpgkey flag, the GPGKEY env var, and in the default identity secret ring.

()

Source from the content-addressed store, hash-verified

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.
116func (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
134func (c *initCmd) getPublicKeyArmored() ([]byte, error) {
135 entity, err := jsonsign.EntityFromSecring(c.keyId, c.secretRing)

Callers 1

RunCommandMethod · 0.95

Calls 2

KeyIdFromRingFunction · 0.92
PrintfMethod · 0.80

Tested by

no test coverage detected