Skip to content

Commit dd54c48

Browse files
committed
std.crypto.asn1: fix merge conflicts
1 parent ed7004a commit dd54c48

File tree

5 files changed

+34
-36
lines changed

5 files changed

+34
-36
lines changed

lib/std/crypto/asn1.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,22 @@ pub const Tag = struct {
138138

139139
pub fn fromZig(comptime T: type) Tag {
140140
switch (@typeInfo(T)) {
141-
.Struct, .Enum, .Union => {
141+
.@"struct", .@"enum", .@"union" => {
142142
if (@hasDecl(T, "asn1_tag")) return T.asn1_tag;
143143
},
144144
else => {},
145145
}
146146

147147
switch (@typeInfo(T)) {
148-
.Struct, .Union => return universal(.sequence, true),
149-
.Bool => return universal(.boolean, false),
150-
.Int => return universal(.integer, false),
151-
.Enum => |e| {
148+
.@"struct", .@"union" => return universal(.sequence, true),
149+
.bool => return universal(.boolean, false),
150+
.int => return universal(.integer, false),
151+
.@"enum" => |e| {
152152
if (@hasDecl(T, "oids")) return Oid.asn1_tag;
153153
return universal(if (e.is_exhaustive) .enumerated else .integer, false);
154154
},
155-
.Optional => |o| return fromZig(o.child),
156-
.Null => return universal(.null, false),
155+
.optional => |o| return fromZig(o.child),
156+
.null => return universal(.null, false),
157157
else => @compileError("cannot map Zig type to asn1_tag " ++ @typeName(T)),
158158
}
159159
}
@@ -266,12 +266,12 @@ pub const FieldTag = struct {
266266
class: Tag.Class,
267267
explicit: bool = true,
268268

269-
pub fn explicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag {
270-
return FieldTag{ .number = number, .class = class, .explicit = true };
269+
pub fn initExplicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag {
270+
return .{ .number = number, .class = class, .explicit = true };
271271
}
272272

273-
pub fn implicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag {
274-
return FieldTag{ .number = number, .class = class, .explicit = false };
273+
pub fn initImplicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag {
274+
return .{ .number = number, .class = class, .explicit = false };
275275
}
276276

277277
pub fn fromContainer(comptime Container: type, comptime field_name: []const u8) ?FieldTag {

lib/std/crypto/asn1/Oid.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn fromDotComptime(comptime dot_notation: []const u8) Oid {
147147
/// - Oid -> enum
148148
/// - Enum -> oid
149149
pub fn StaticMap(comptime Enum: type) type {
150-
const enum_info = @typeInfo(Enum).Enum;
150+
const enum_info = @typeInfo(Enum).@"enum";
151151
const EnumToOid = std.EnumArray(Enum, []const u8);
152152
const ReturnType = struct {
153153
oid_to_enum: std.StaticStringMap(Enum),
@@ -165,7 +165,7 @@ pub fn StaticMap(comptime Enum: type) type {
165165

166166
return struct {
167167
pub fn initComptime(comptime key_pairs: anytype) ReturnType {
168-
const struct_info = @typeInfo(@TypeOf(key_pairs)).Struct;
168+
const struct_info = @typeInfo(@TypeOf(key_pairs)).@"struct";
169169
const error_msg = "Each field of '" ++ @typeName(Enum) ++ "' must map to exactly one OID";
170170
if (!enum_info.is_exhaustive or enum_info.fields.len != struct_info.fields.len) {
171171
@compileError(error_msg);

lib/std/crypto/asn1/der/Decoder.zig

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn any(self: *Decoder, comptime T: type) !T {
1919

2020
const tag = Tag.fromZig(T).toExpected();
2121
switch (@typeInfo(T)) {
22-
.Struct => {
22+
.@"struct" => {
2323
const ele = try self.element(tag);
2424
defer self.index = ele.slice.end; // don't force parsing all fields
2525

@@ -37,22 +37,20 @@ pub fn any(self: *Decoder, comptime T: type) !T {
3737
}
3838

3939
@field(res, f.name) = self.any(f.type) catch |err| brk: {
40-
if (f.default_value) |d| {
41-
break :brk @as(*const f.type, @alignCast(@ptrCast(d))).*;
40+
if (f.defaultValue()) |d| {
41+
break :brk d;
4242
}
4343
return err;
4444
};
4545
// DER encodes null values by skipping them.
46-
if (@typeInfo(f.type) == .Optional and @field(res, f.name) == null) {
47-
if (f.default_value) |d| {
48-
@field(res, f.name) = @as(*const f.type, @alignCast(@ptrCast(d))).*;
49-
}
46+
if (@typeInfo(f.type) == .optional and @field(res, f.name) == null) {
47+
if (f.defaultValue()) |d| @field(res, f.name) = d;
5048
}
5149
}
5250

5351
return res;
5452
},
55-
.Bool => {
53+
.bool => {
5654
const ele = try self.element(tag);
5755
const bytes = self.view(ele);
5856
if (bytes.len != 1) return error.InvalidBool;
@@ -63,20 +61,20 @@ pub fn any(self: *Decoder, comptime T: type) !T {
6361
else => error.InvalidBool,
6462
};
6563
},
66-
.Int => {
64+
.int => {
6765
const ele = try self.element(tag);
6866
const bytes = self.view(ele);
6967
return try int(T, bytes);
7068
},
71-
.Enum => |e| {
69+
.@"enum" => |e| {
7270
const ele = try self.element(tag);
7371
const bytes = self.view(ele);
7472
if (@hasDecl(T, "oids")) {
7573
return T.oids.oidToEnum(bytes) orelse return error.UnknownOid;
7674
}
7775
return @enumFromInt(try int(e.tag_type, bytes));
7876
},
79-
.Optional => |o| return self.any(o.child) catch return null,
77+
.optional => |o| return self.any(o.child) catch return null,
8078
else => @compileError("cannot decode type " ++ @typeName(T)),
8179
}
8280
}
@@ -113,7 +111,7 @@ pub fn view(self: Decoder, elem: Element) []const u8 {
113111
}
114112

115113
fn int(comptime T: type, value: []const u8) error{ NonCanonical, LargeValue }!T {
116-
if (@typeInfo(T).Int.bits % 8 != 0) @compileError("T must be byte aligned");
114+
if (@typeInfo(T).int.bits % 8 != 0) @compileError("T must be byte aligned");
117115

118116
var bytes = value;
119117
if (bytes.len >= 2) {

lib/std/crypto/asn1/der/Encoder.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
2828
const merged_tag = self.mergedTag(tag_);
2929

3030
switch (@typeInfo(T)) {
31-
.Struct => |info| {
31+
.@"struct" => |info| {
3232
inline for (0..info.fields.len) |i| {
3333
const f = info.fields[info.fields.len - i - 1];
3434
const field_val = @field(val, f.name);
3535
const field_tag = FieldTag.fromContainer(T, f.name);
3636

3737
// > The encoding of a set value or sequence value shall not include an encoding for any
3838
// > component value which is equal to its default value.
39-
const is_default = if (f.is_comptime) false else if (f.default_value) |v| brk: {
39+
const is_default = if (f.is_comptime) false else if (f.default_value_ptr) |v| brk: {
4040
const default_val: *const f.type = @alignCast(@ptrCast(v));
4141
break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val));
4242
} else false;
@@ -57,17 +57,17 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void {
5757
}
5858
}
5959
},
60-
.Bool => try self.buffer.prependSlice(&[_]u8{if (val) 0xff else 0}),
61-
.Int => try self.int(T, val),
62-
.Enum => |e| {
60+
.bool => try self.buffer.prependSlice(&[_]u8{if (val) 0xff else 0}),
61+
.int => try self.int(T, val),
62+
.@"enum" => |e| {
6363
if (@hasDecl(T, "oids")) {
6464
return self.any(T.oids.enumToOid(val));
6565
} else {
6666
try self.int(e.tag_type, @intFromEnum(val));
6767
}
6868
},
69-
.Optional => if (val) |v| return try self.anyTag(tag_, v),
70-
.Null => {},
69+
.optional => if (val) |v| return try self.anyTag(tag_, v),
70+
.null => {},
7171
else => @compileError("cannot encode type " ++ @typeName(T)),
7272
}
7373

lib/std/crypto/asn1/test.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ const AllTypes = struct {
1717
h: asn1.Any,
1818

1919
pub const asn1_tags = .{
20-
.a = FieldTag.explicit(0, .context_specific),
21-
.b = FieldTag.explicit(1, .context_specific),
22-
.c = FieldTag.implicit(2, .context_specific),
23-
.g = FieldTag.implicit(3, .context_specific),
20+
.a = FieldTag.initExplicit(0, .context_specific),
21+
.b = FieldTag.initExplicit(1, .context_specific),
22+
.c = FieldTag.initImplicit(2, .context_specific),
23+
.g = FieldTag.initImplicit(3, .context_specific),
2424
};
2525

2626
const C = enum {

0 commit comments

Comments
 (0)