clean code

This commit is contained in:
Stéphane Depierrepont aka Toorop
2015-05-06 16:15:02 +02:00
parent 10eac5151d
commit a96bf59256
3 changed files with 6 additions and 9 deletions

View File

@@ -11,12 +11,10 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/pem"
//"fmt"
"hash"
"io/ioutil"
"regexp"
"strings"
//"time"
)
const (
@@ -89,7 +87,6 @@ func NewSigOptions() sigOptions {
// Sign signs an email
func Sign(email *bytes.Reader, options sigOptions) (*bytes.Reader, error) {
var privateKey *rsa.PrivateKey
// check && sanitize config
// PrivateKey (required & TODO: valid)
if options.PrivateKey == "" {
@@ -99,7 +96,7 @@ func Sign(email *bytes.Reader, options sigOptions) (*bytes.Reader, error) {
d, _ := pem.Decode([]byte(options.PrivateKey))
key, err := x509.ParsePKCS1PrivateKey(d.Bytes)
if err != nil {
return nil, err
return nil, ErrCandNotParsePrivateKey
}
privateKey = key
@@ -237,8 +234,7 @@ func canonicalize(emailReader *bytes.Reader, options sigOptions) (headers, body
return
}
//fmt.Println(email)
// todo \n -> \r\n
// TODO: \n -> \r\n
parts := bytes.SplitN(email, []byte{13, 10, 13, 10}, 2)
if len(parts) != 2 {

View File

@@ -206,7 +206,7 @@ func NewDkimHeaderBySigOptions(options sigOptions) *DkimHeader {
}
// GetHeaderBase return base header for signers
// Todo: some refactoring...
// Todo: some refactoring needed...
func (d *DkimHeader) GetHeaderBase(bodyHash string) string {
h := "DKIM-Signature: v=" + d.Version + "; a=" + d.Algorithm + "; q=" + strings.Join(d.QueryMethods, ":") + "; c=" + d.MessageCanonicalization + ";" + CRLF + TAB
subh := "s=" + d.Selector + ";"
@@ -298,5 +298,3 @@ func (d *DkimHeader) GetHeaderBase(bodyHash string) string {
h += subh + ";" + FWS + "b="
return h
}
//'test._domainkey.tmail.io:v=DKIM1;k=rsa;s=email;h=sha256;t=y;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNUXO+Qsl1tw+GjrqFajz0ERSEUs1FHSL/+udZRWn1Atw8gz0+tcGqhWChBDeU9gY5sKLEAZnX3FjC/T/IbqeiSM68kS5vLkzRI84eiJrm3+IieUqIIicsO+WYxQs+JgVx5XhpPjX4SQjHtwEC2xKkWnEv+VPgO1JWdooURcSC6QIDAQAB':300::

View File

@@ -20,6 +20,9 @@ var (
// If bad Canonicalization parameter
ErrSignBadCanonicalization = errors.New("bad Canonicalization parameter")
// when unable to parse private key
ErrCandNotParsePrivateKey = errors.New("can not parse private key, check format (pem) and validity")
// Bad algorithm
ErrSignBadAlgo = errors.New("bad algorithm. Only rsa-sha1 or rsa-sha256 are permitted")