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 41 42 43 44 45 46 47 48 49 50 51
|
package pgpmail
import (
_ "embed"
"fmt"
"strings"
"time"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/packet"
)
//go:embed testdata/private_key.asc
var testPrivateKeyArmored string
//go:embed testdata/public_key.asc
var testPublicKeyArmored string
type zeroReader struct{}
func (zeroReader) Read(buf []byte) (int, error) {
for i := range buf {
buf[i] = 0
}
return len(buf), nil
}
var testPrivateKey = mustReadArmoredEntity(testPrivateKeyArmored)
var testPublicKey = mustReadArmoredEntity(testPublicKeyArmored)
var testConfig = &packet.Config{
Rand: &zeroReader{},
Time: func() time.Time {
return time.Date(2020, 2, 20, 0, 0, 0, 0, time.UTC)
},
}
func mustReadArmoredEntity(s string) *openpgp.Entity {
el, err := openpgp.ReadArmoredKeyRing(strings.NewReader(s))
if err != nil {
panic(fmt.Errorf("pgpmail: failed to read test key: %v", err))
}
if len(el) != 1 {
panic("pgpmail: test keyring doesn't contain exactly one key")
}
return el[0]
}
func toCRLF(s string) string {
return strings.ReplaceAll(s, "\n", "\r\n")
}
|