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