upgrade go-dkim

This commit is contained in:
Shivaram Lingamneni 2020-11-08 17:56:46 -05:00
parent 008416e4dd
commit 4f9d406b93
4 changed files with 15 additions and 6 deletions

View file

@ -100,6 +100,7 @@ func NewSigOptions() SigOptions {
// Sign signs an email
func Sign(email *[]byte, options SigOptions) error {
var privateKey *rsa.PrivateKey
var err error
// PrivateKey
if len(options.PrivateKey) == 0 {
@ -109,11 +110,17 @@ func Sign(email *[]byte, options SigOptions) error {
if d == nil {
return ErrCandNotParsePrivateKey
}
key, err := x509.ParsePKCS1PrivateKey(d.Bytes)
if err != nil {
return ErrCandNotParsePrivateKey
// try to parse it as PKCS1 otherwise try PKCS8
if key, err := x509.ParsePKCS1PrivateKey(d.Bytes); err != nil {
if key, err := x509.ParsePKCS8PrivateKey(d.Bytes); err != nil {
return ErrCandNotParsePrivateKey
} else {
privateKey = key.(*rsa.PrivateKey)
}
} else {
privateKey = key
}
privateKey = key
// Domain required
if options.Domain == "" {