@@ -2,38 +2,33 @@ package publish
2
2
3
3
import (
4
4
"crypto"
5
+ "encoding/hex"
5
6
"fmt"
6
7
"io"
8
+ "log/slog"
7
9
8
- _ "crypto/sha256"
9
-
10
- _ "golang.org/x/crypto/ripemd160"
11
-
12
- "golang.org/x/crypto/openpgp"
13
- "golang.org/x/crypto/openpgp/clearsign"
14
- "golang.org/x/crypto/openpgp/packet"
10
+ "github.com/ProtonMail/go-crypto/openpgp/clearsign"
11
+ "github.com/ProtonMail/go-crypto/openpgp/packet"
12
+ openpgp "github.com/ProtonMail/go-crypto/openpgp/v2"
15
13
)
16
14
17
15
type signer struct {
18
- keys []* packet. PrivateKey
16
+ entities []* openpgp. Entity
19
17
}
20
18
21
19
func newSigner (keychain io.Reader ) (* signer , error ) {
22
20
pr := packet .NewReader (keychain )
23
21
s := & signer {}
24
22
for {
25
- pkt , err := pr . Next ( )
23
+ ent , err := openpgp . ReadEntity ( pr )
26
24
if err == io .EOF {
27
25
break
28
26
}
29
27
if err != nil {
30
28
return nil , err
31
29
}
32
- if key , ok := pkt .(* packet.PrivateKey ); ok {
33
- if ! key .IsSubkey && key .PublicKey .PublicKey != nil {
34
- s .keys = append (s .keys , key )
35
- }
36
- }
30
+ slog .Info ("Loaded key" , "fingerprint" , hex .EncodeToString (ent .PrimaryKey .Fingerprint ))
31
+ s .entities = append (s .entities , ent )
37
32
}
38
33
return s , nil
39
34
}
@@ -44,30 +39,28 @@ type seekable interface {
44
39
}
45
40
46
41
func (s * signer ) DetachSign (in seekable , out io.Writer ) error {
47
- if len (s .keys ) == 0 {
48
- return fmt .Errorf ("no private keys found " )
42
+ if len (s .entities ) == 0 {
43
+ return fmt .Errorf ("no entities " )
49
44
}
50
45
cfg := & packet.Config {
51
46
DefaultHash : crypto .SHA256 ,
52
47
}
53
- for _ , key := range s .keys {
54
- if _ , err := in .Seek (0 , io .SeekStart ); err != nil {
55
- return err
56
- }
57
- signer := & openpgp.Entity {PrivateKey : key }
58
- if err := openpgp .DetachSign (out , signer , in , cfg ); err != nil {
59
- return err
60
- }
48
+ if err := openpgp .DetachSign (out , s .entities , in , cfg ); err != nil {
49
+ return err
61
50
}
62
51
return nil
63
52
}
64
53
65
54
func (s * signer ) ClearSign (in seekable , out io.Writer ) error {
66
- if len (s .keys ) == 0 {
67
- return fmt .Errorf ("no private keys found " )
55
+ if len (s .entities ) == 0 {
56
+ return fmt .Errorf ("no entities " )
68
57
}
69
58
70
- w , err := clearsign .EncodeMulti (out , s .keys , nil )
59
+ keys := make ([]* packet.PrivateKey , len (s .entities ))
60
+ for i , e := range s .entities {
61
+ keys [i ] = e .PrivateKey
62
+ }
63
+ w , err := clearsign .EncodeMulti (out , keys , nil )
71
64
if err != nil {
72
65
return err
73
66
}
0 commit comments