MCPcopy Create free account
hub / github.com/LanceLRQ/deer-executor / GetArmorPublicKey

Function GetArmorPublicKey

common/persistence/utils.go:207–246  ·  view source on GitHub ↗

GetArmorPublicKey 从文件读取GPG证书公钥信息

(gpgKeyFile string, passphrase []byte)

Source from the content-addressed store, hash-verified

205
206// GetArmorPublicKey 从文件读取GPG证书公钥信息
207func GetArmorPublicKey(gpgKeyFile string, passphrase []byte) (*DigitalSignPEM, error) {
208 if gpgKeyFile == "" {
209 return nil, errors.Errorf("please set GPG key file path")
210 }
211 // Open key
212 keyRingReader, err := os.Open(gpgKeyFile)
213 if err != nil {
214 return nil, err
215 }
216 // Read GPG Keys
217 elist, err := openpgp.ReadArmoredKeyRing(keyRingReader)
218 if err != nil {
219 return nil, err
220 }
221 if len(elist) < 1 {
222 return nil, errors.Errorf("file has no GPG key")
223 }
224 gpgKey := elist[0].PrivateKey
225 if gpgKey.Encrypted {
226 if len(passphrase) == 0 {
227 passphrase, err = gopass.GetPasswdPrompt("please input passphrase of key> ", true, os.Stdin, os.Stdout)
228 if err != nil {
229 return nil, err
230 }
231 }
232 err = gpgKey.Decrypt(passphrase)
233 if err != nil {
234 return nil, err
235 }
236 }
237 publicKeyArmor, err := GetPublicKeyArmorBytes(elist[0])
238 if err != nil {
239 return nil, err
240 }
241 return &DigitalSignPEM{
242 PrivateKey: gpgKey.PrivateKey.(*rsa.PrivateKey),
243 PublicKeyRaw: publicKeyArmor,
244 PublicKey: elist[0].PrimaryKey.PublicKey.(*rsa.PublicKey),
245 }, nil
246}

Callers 2

BuildProblemPackageFunction · 0.92
runUserJudgeFunction · 0.92

Calls 2

GetPublicKeyArmorBytesFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected