Skip to content

Commit

Permalink
dkim: compare with strings.EqualFold instead of ToLower
Browse files Browse the repository at this point in the history
It doesn't allocate a new string each time.

Fixes emersion#48
  • Loading branch information
pierrre authored and emersion committed Mar 31, 2021
1 parent e98a2ee commit 5995b67
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions dkim/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,12 @@ func newHeaderPicker(h header) *headerPicker {
}

func (p *headerPicker) Pick(key string) string {
key = strings.ToLower(key)
at := p.picked[key]
for i := len(p.h) - 1; i >= 0; i-- {
kv := p.h[i]
k, _ := parseHeaderField(kv)

if strings.ToLower(k) != key {
if !strings.EqualFold(k, key) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion dkim/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func verify(h header, r io.Reader, sigField, sigValue string, options *VerifyOpt
headerKeys := parseTagList(params["h"])
ok := false
for _, k := range headerKeys {
if strings.ToLower(k) == "from" {
if strings.EqualFold(k, "from") {
ok = true
break
}
Expand Down

0 comments on commit 5995b67

Please sign in to comment.