KeyIdFromRing returns the public keyID contained in the secret ring file secRing. It expects only one keyID in this secret ring and returns an error otherwise.
(secRing string)
| 174 | // ring file secRing. It expects only one keyID in this secret ring |
| 175 | // and returns an error otherwise. |
| 176 | func KeyIdFromRing(secRing string) (keyID string, err error) { |
| 177 | f, err := wkfs.Open(secRing) |
| 178 | if err != nil { |
| 179 | return "", fmt.Errorf("Could not open secret ring file %v: %v", secRing, err) |
| 180 | } |
| 181 | defer f.Close() |
| 182 | el, err := readKeyRing(f) |
| 183 | if err != nil { |
| 184 | return "", fmt.Errorf("Could not read secret ring file %s: %v", secRing, err) |
| 185 | } |
| 186 | if len(el) != 1 { |
| 187 | return "", fmt.Errorf("Secret ring file %v contained %d identities; expected 1", secRing, len(el)) |
| 188 | } |
| 189 | ent := el[0] |
| 190 | return ent.PrimaryKey.KeyIdString(), nil |
| 191 | } |
| 192 | |
| 193 | // GenerateNewSecRing creates a new secret ring file secRing, with |
| 194 | // a new GPG identity. It returns the public keyID of that identity. |
no test coverage detected