Skip to content

Commit

Permalink
Emit armor headers in deterministically sorted order (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgdotcom authored Dec 3, 2024
1 parent 5521d83 commit b01f065
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions openpgp/armor/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package armor
import (
"encoding/base64"
"io"
"sort"
)

var armorHeaderSep = []byte(": ")
Expand Down Expand Up @@ -159,8 +160,15 @@ func encode(out io.Writer, blockType string, headers map[string]string, checksum
return
}

for k, v := range headers {
err = writeSlices(out, []byte(k), armorHeaderSep, []byte(v), newline)
keys := make([]string, len(headers))
i := 0
for k := range headers {
keys[i] = k
i++
}
sort.Strings(keys)
for _, k := range keys {
err = writeSlices(out, []byte(k), armorHeaderSep, []byte(headers[k]), newline)
if err != nil {
return
}
Expand Down

0 comments on commit b01f065

Please sign in to comment.