MCPcopy
hub / github.com/OpenListTeam/OpenList / loadPrivateKey

Function loadPrivateKey

drivers/github/util.go:107–131  ·  view source on GitHub ↗
(key, passphrase string)

Source from the content-addressed store, hash-verified

105}
106
107func loadPrivateKey(key, passphrase string) (*openpgp.Entity, error) {
108 entityList, err := openpgp.ReadArmoredKeyRing(strings.NewReader(key))
109 if err != nil {
110 return nil, err
111 }
112 if len(entityList) < 1 {
113 return nil, fmt.Errorf("no keys found in key ring")
114 }
115 entity := entityList[0]
116
117 pass := []byte(passphrase)
118 if entity.PrivateKey != nil && entity.PrivateKey.Encrypted {
119 if err = entity.PrivateKey.Decrypt(pass); err != nil {
120 return nil, fmt.Errorf("password incorrect: %+v", err)
121 }
122 }
123 for _, subKey := range entity.Subkeys {
124 if subKey.PrivateKey != nil && subKey.PrivateKey.Encrypted {
125 if err = subKey.PrivateKey.Decrypt(pass); err != nil {
126 return nil, fmt.Errorf("password incorrect: %+v", err)
127 }
128 }
129 }
130 return entity, nil
131}
132
133func signCommit(m *map[string]interface{}, entity *openpgp.Entity) (string, error) {
134 var commit strings.Builder

Callers 1

InitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected