| ... | @@ -66,6 +66,31 @@ test "integer round trip across signed and unsigned boundaries" { | ... | @@ -66,6 +66,31 @@ test "integer round trip across signed and unsigned boundaries" { |
| 66 | } | 66 | } |
| 67 | } | 67 | } |
| 68 | | 68 | |
| | 69 | test "encode skips null optional fields" { |
| | 70 | const Value = struct { a: ?u8, b: u8 }; |
| | 71 | const allocator = std.testing.allocator; |
| | 72 | const actual = try encode(allocator, Value{ .a = null, .b = 5 }); |
| | 73 | defer allocator.free(actual); |
| | 74 | |
| | 75 | try std.testing.expectEqualSlices(u8, &.{ 0x30, 0x03, 0x02, 0x01, 0x05 }, actual); |
| | 76 | } |
| | 77 | |
| | 78 | test "encode preserves outer sequence tag after implicit field tags" { |
| | 79 | const Value = struct { |
| | 80 | a: u8, |
| | 81 | b: u8, |
| | 82 | |
| | 83 | pub const asn1_tags = .{ |
| | 84 | .a = asn1.FieldTag.initImplicit(0, .context_specific), |
| | 85 | }; |
| | 86 | }; |
| | 87 | const allocator = std.testing.allocator; |
| | 88 | const actual = try encode(allocator, Value{ .a = 1, .b = 2 }); |
| | 89 | defer allocator.free(actual); |
| | 90 | |
| | 91 | try std.testing.expectEqualSlices(u8, &.{ 0x30, 0x06, 0x80, 0x01, 0x01, 0x02, 0x01, 0x02 }, actual); |
| | 92 | } |
| | 93 | |
| 69 | test { | 94 | test { |
| 70 | _ = Decoder; | 95 | _ = Decoder; |
| 71 | _ = Encoder; | 96 | _ = Encoder; |