| 105 | } |
| 106 | |
| 107 | func 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 | |
| 133 | func signCommit(m *map[string]interface{}, entity *openpgp.Entity) (string, error) { |
| 134 | var commit strings.Builder |