-
Notifications
You must be signed in to change notification settings - Fork 39
/
signer.go
40 lines (35 loc) · 914 Bytes
/
signer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pmpgp
import (
"bytes"
"crypto"
"hash"
"time"
"github.com/ProtonMail/go-crypto/openpgp/packet"
"github.com/sassoftware/go-rpmutils/internal"
)
type Signer struct {
PrivateKey *packet.PrivateKey
}
func (s Signer) Sign(h hash.Hash, hashType crypto.Hash, creationTime time.Time) ([]byte, error) {
sig := &packet.Signature{
Version: s.PrivateKey.Version,
SigType: packet.SigTypeBinary,
CreationTime: creationTime,
PubKeyAlgo: s.PrivateKey.PublicKey.PubKeyAlgo,
Hash: hashType,
IssuerKeyId: &s.PrivateKey.KeyId,
IssuerFingerprint: s.PrivateKey.PublicKey.Fingerprint,
}
err := sig.Sign(h, s.PrivateKey, nil)
if err != nil {
return nil, err
}
var buf bytes.Buffer
err = sig.Serialize(&buf)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// ensure the interface is implemented
var _ internal.Signer = Signer{}