From db09cd66d1578bbb409cee25a891ba38483c5894 Mon Sep 17 00:00:00 2001 From: Steve Weis Date: Fri, 20 Mar 2026 13:49:27 -0700 Subject: [PATCH] internal/inspect: fix tag stanza type names in post-quantum classifier (#695) Co-authored-by: Claude --- internal/inspect/inspect.go | 4 +-- internal/inspect/inspect_test.go | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/internal/inspect/inspect.go b/internal/inspect/inspect.go index b0c3d49..cb80dac 100644 --- a/internal/inspect/inspect.go +++ b/internal/inspect/inspect.go @@ -61,9 +61,9 @@ func Inspect(r io.Reader, fileSize int64) (*Metadata, error) { for _, s := range hdr.Recipients { data.StanzaTypes = append(data.StanzaTypes, s.Type) switch s.Type { - case "X25519", "ssh-rsa", "ssh-ed25519", "age-encryption.org/p256tag", "piv-p256": + case "X25519", "ssh-rsa", "ssh-ed25519", "p256tag", "piv-p256": data.Postquantum = "no" - case "mlkem768x25519", "scrypt", "age-encryption.org/mlkem768p256tag": + case "mlkem768x25519", "scrypt", "mlkem768p256tag": if data.Postquantum != "no" { data.Postquantum = "yes" } diff --git a/internal/inspect/inspect_test.go b/internal/inspect/inspect_test.go index 331ff1e..f71cbbc 100644 --- a/internal/inspect/inspect_test.go +++ b/internal/inspect/inspect_test.go @@ -1,12 +1,57 @@ package inspect import ( + "bytes" "fmt" "testing" + "filippo.io/age/internal/format" "filippo.io/age/internal/stream" ) +// buildFile serializes a header with a single stanza of the given type, +// followed by the minimal valid encrypted payload (a 16-byte stream nonce +// and a single empty ChaCha20-Poly1305 chunk). +func buildFile(t *testing.T, stanzaType string) []byte { + t.Helper() + hdr := &format.Header{ + Recipients: []*format.Stanza{{Type: stanzaType}}, + MAC: make([]byte, 32), + } + buf := &bytes.Buffer{} + if err := hdr.Marshal(buf); err != nil { + t.Fatalf("Header.Marshal: %v", err) + } + // Append nonce (16 bytes) + poly1305 tag for empty chunk (16 bytes). + buf.Write(make([]byte, 16+16)) + return buf.Bytes() +} + +func TestInspectTagStanzas(t *testing.T) { + tests := []struct { + stanzaType string + want string + }{ + {stanzaType: "p256tag", want: "no"}, + {stanzaType: "mlkem768p256tag", want: "yes"}, + } + for _, tt := range tests { + t.Run(tt.stanzaType, func(t *testing.T) { + f := buildFile(t, tt.stanzaType) + md, err := Inspect(bytes.NewReader(f), int64(len(f))) + if err != nil { + t.Fatalf("Inspect: %v", err) + } + if got := md.Postquantum; got != tt.want { + t.Errorf("Postquantum = %q, want %q", got, tt.want) + } + if len(md.StanzaTypes) != 1 || md.StanzaTypes[0] != tt.stanzaType { + t.Errorf("StanzaTypes = %v, want [%q]", md.StanzaTypes, tt.stanzaType) + } + }) + } +} + func TestStreamOverhead(t *testing.T) { tests := []struct { payloadSize int64