From 434c9fe4d79d3513bd36aeaf2f8a90dd28f7cb37 Mon Sep 17 00:00:00 2001 From: Ben Burkert Date: Sat, 8 Aug 2026 20:43:16 -0400 Subject: [PATCH] asn1: replace use of deprecated lang.Type.Enum API The API for std.lang.Type changed in PR #35234, but the ASN.1 tag encoder is using the old API. Update the check for an exhaustive enum for the new API, and add a test that exercises this prong of the encoder. --- lib/std/crypto/codecs/asn1.zig | 2 +- lib/std/crypto/codecs/asn1/der/Encoder.zig | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/std/crypto/codecs/asn1.zig b/lib/std/crypto/codecs/asn1.zig index 68110155122c38418078aea1ebe433c106aafa3a..cd5e1195833bd12064969b362ce2f7bbaf517217 100644 --- a/lib/std/crypto/codecs/asn1.zig +++ b/lib/std/crypto/codecs/asn1.zig @@ -162,7 +162,7 @@ pub const Tag = struct { .int => return universal(.integer, false), .@"enum" => |e| { if (@hasDecl(T, "oids")) return Oid.asn1_tag; - return universal(if (e.is_exhaustive) .enumerated else .integer, false); + return universal(if (e.mode == .exhaustive) .enumerated else .integer, false); }, .optional => |o| return fromZig(o.child), .null => return universal(.null, false), diff --git a/lib/std/crypto/codecs/asn1/der/Encoder.zig b/lib/std/crypto/codecs/asn1/der/Encoder.zig index f3e58ea7a5e9cf7665335f95150c5ce17a60c059..16aa189f8f09332a27676bfe3fbca25c49327533 100644 --- a/lib/std/crypto/codecs/asn1/der/Encoder.zig +++ b/lib/std/crypto/codecs/asn1/der/Encoder.zig @@ -21,6 +21,26 @@ pub fn any(self: *Encoder, val: anytype) !void { try self.anyTag(Tag.fromZig(T), val); } +test any { + const Enum = enum(u8) { + x = 0, + }; + + try checkAnyEncoding(u16, 0, &.{ 0x02, 0x01, 0x00 }); + try checkAnyEncoding(Enum, .x, &.{ 0x0a, 0x01, 0x00 }); +} + +fn checkAnyEncoding(T: type, value: T, expected: []const u8) !void { + var encoder: @This() = .init(std.testing.allocator); + defer encoder.deinit(); + + try encoder.any(value); + const encoded = try encoder.buffer.toOwnedSlice(); + defer std.testing.allocator.free(encoded); + + try std.testing.expectEqualSlices(u8, expected, encoded); +} + fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { const T = @TypeOf(val); if (std.meta.hasFn(T, "encodeDer")) return try val.encodeDer(self); -- 2.54.0