From c0c1dd33f5ce7109b74f9ec6cd91a3dbd2dc049a Mon Sep 17 00:00:00 2001 From: Andrew Gallagher Date: Mon, 2 Dec 2024 17:33:45 +0000 Subject: [PATCH] Emit armor headers in sorted order --- openpgp/armor/encode.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openpgp/armor/encode.go b/openpgp/armor/encode.go index 112f98b8..550efddf 100644 --- a/openpgp/armor/encode.go +++ b/openpgp/armor/encode.go @@ -7,6 +7,7 @@ package armor import ( "encoding/base64" "io" + "sort" ) var armorHeaderSep = []byte(": ") @@ -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 }