| author | |
| committer | |
| log | dd54c48aa249ce7b7a66c0f2568c1e5fa84e6012 |
| tree | 7c66f99f10ddcbd2f1026151e1aad8c413c7d89d |
| parent | ed7004a2ee3b984a17b3fbd468d73a3875f209eb |
5 files changed, 34 insertions(+), 36 deletions(-)
lib/std/crypto/asn1.zig+11-11| ... | @@ -138,22 +138,22 @@ pub const Tag = struct { | ... | @@ -138,22 +138,22 @@ pub const Tag = struct { |
| 138 | 138 | ||
| 139 | pub fn fromZig(comptime T: type) Tag { | 139 | pub fn fromZig(comptime T: type) Tag { |
| 140 | switch (@typeInfo(T)) { | 140 | switch (@typeInfo(T)) { |
| 141 | .Struct, .Enum, .Union => { | 141 | .@"struct", .@"enum", .@"union" => { |
| 142 | if (@hasDecl(T, "asn1_tag")) return T.asn1_tag; | 142 | if (@hasDecl(T, "asn1_tag")) return T.asn1_tag; |
| 143 | }, | 143 | }, |
| 144 | else => {}, | 144 | else => {}, |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | switch (@typeInfo(T)) { | 147 | switch (@typeInfo(T)) { |
| 148 | .Struct, .Union => return universal(.sequence, true), | 148 | .@"struct", .@"union" => return universal(.sequence, true), |
| 149 | .Bool => return universal(.boolean, false), | 149 | .bool => return universal(.boolean, false), |
| 150 | .Int => return universal(.integer, false), | 150 | .int => return universal(.integer, false), |
| 151 | .Enum => |e| { | 151 | .@"enum" => |e| { |
| 152 | if (@hasDecl(T, "oids")) return Oid.asn1_tag; | 152 | if (@hasDecl(T, "oids")) return Oid.asn1_tag; |
| 153 | return universal(if (e.is_exhaustive) .enumerated else .integer, false); | 153 | return universal(if (e.is_exhaustive) .enumerated else .integer, false); |
| 154 | }, | 154 | }, |
| 155 | .Optional => |o| return fromZig(o.child), | 155 | .optional => |o| return fromZig(o.child), |
| 156 | .Null => return universal(.null, false), | 156 | .null => return universal(.null, false), |
| 157 | else => @compileError("cannot map Zig type to asn1_tag " ++ @typeName(T)), | 157 | else => @compileError("cannot map Zig type to asn1_tag " ++ @typeName(T)), |
| 158 | } | 158 | } |
| 159 | } | 159 | } |
| ... | @@ -266,12 +266,12 @@ pub const FieldTag = struct { | ... | @@ -266,12 +266,12 @@ pub const FieldTag = struct { |
| 266 | class: Tag.Class, | 266 | class: Tag.Class, |
| 267 | explicit: bool = true, | 267 | explicit: bool = true, |
| 268 | 268 | ||
| 269 | pub fn explicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag { | 269 | pub fn initExplicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag { |
| 270 | return FieldTag{ .number = number, .class = class, .explicit = true }; | 270 | return .{ .number = number, .class = class, .explicit = true }; |
| 271 | } | 271 | } |
| 272 | 272 | ||
| 273 | pub fn implicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag { | 273 | pub fn initImplicit(number: std.meta.Tag(Tag.Number), class: Tag.Class) FieldTag { |
| 274 | return FieldTag{ .number = number, .class = class, .explicit = false }; | 274 | return .{ .number = number, .class = class, .explicit = false }; |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | pub fn fromContainer(comptime Container: type, comptime field_name: []const u8) ?FieldTag { | 277 | pub fn fromContainer(comptime Container: type, comptime field_name: []const u8) ?FieldTag { |
lib/std/crypto/asn1/Oid.zig+2-2| ... | @@ -147,7 +147,7 @@ pub fn fromDotComptime(comptime dot_notation: []const u8) Oid { | ... | @@ -147,7 +147,7 @@ pub fn fromDotComptime(comptime dot_notation: []const u8) Oid { |
| 147 | /// - Oid -> enum | 147 | /// - Oid -> enum |
| 148 | /// - Enum -> oid | 148 | /// - Enum -> oid |
| 149 | pub fn StaticMap(comptime Enum: type) type { | 149 | pub fn StaticMap(comptime Enum: type) type { |
| 150 | const enum_info = @typeInfo(Enum).Enum; | 150 | const enum_info = @typeInfo(Enum).@"enum"; |
| 151 | const EnumToOid = std.EnumArray(Enum, []const u8); | 151 | const EnumToOid = std.EnumArray(Enum, []const u8); |
| 152 | const ReturnType = struct { | 152 | const ReturnType = struct { |
| 153 | oid_to_enum: std.StaticStringMap(Enum), | 153 | oid_to_enum: std.StaticStringMap(Enum), |
| ... | @@ -165,7 +165,7 @@ pub fn StaticMap(comptime Enum: type) type { | ... | @@ -165,7 +165,7 @@ pub fn StaticMap(comptime Enum: type) type { |
| 165 | 165 | ||
| 166 | return struct { | 166 | return struct { |
| 167 | pub fn initComptime(comptime key_pairs: anytype) ReturnType { | 167 | 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"; |
| 169 | const error_msg = "Each field of '" ++ @typeName(Enum) ++ "' must map to exactly one OID"; | 169 | const error_msg = "Each field of '" ++ @typeName(Enum) ++ "' must map to exactly one OID"; |
| 170 | if (!enum_info.is_exhaustive or enum_info.fields.len != struct_info.fields.len) { | 170 | if (!enum_info.is_exhaustive or enum_info.fields.len != struct_info.fields.len) { |
| 171 | @compileError(error_msg); | 171 | @compileError(error_msg); |
lib/std/crypto/asn1/der/Decoder.zig+10-12| ... | @@ -19,7 +19,7 @@ pub fn any(self: *Decoder, comptime T: type) !T { | ... | @@ -19,7 +19,7 @@ pub fn any(self: *Decoder, comptime T: type) !T { |
| 19 | 19 | ||
| 20 | const tag = Tag.fromZig(T).toExpected(); | 20 | const tag = Tag.fromZig(T).toExpected(); |
| 21 | switch (@typeInfo(T)) { | 21 | switch (@typeInfo(T)) { |
| 22 | .Struct => { | 22 | .@"struct" => { |
| 23 | const ele = try self.element(tag); | 23 | const ele = try self.element(tag); |
| 24 | defer self.index = ele.slice.end; // don't force parsing all fields | 24 | defer self.index = ele.slice.end; // don't force parsing all fields |
| 25 | 25 | ||
| ... | @@ -37,22 +37,20 @@ pub fn any(self: *Decoder, comptime T: type) !T { | ... | @@ -37,22 +37,20 @@ pub fn any(self: *Decoder, comptime T: type) !T { |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | @field(res, f.name) = self.any(f.type) catch |err| brk: { | 39 | @field(res, f.name) = self.any(f.type) catch |err| brk: { |
| 40 | if (f.default_value) |d| { | 40 | if (f.defaultValue()) |d| { |
| 41 | break :brk @as(*const f.type, @alignCast(@ptrCast(d))).*; | 41 | break :brk d; |
| 42 | } | 42 | } |
| 43 | return err; | 43 | return err; |
| 44 | }; | 44 | }; |
| 45 | // DER encodes null values by skipping them. | 45 | // DER encodes null values by skipping them. |
| 46 | if (@typeInfo(f.type) == .Optional and @field(res, f.name) == null) { | 46 | if (@typeInfo(f.type) == .optional and @field(res, f.name) == null) { |
| 47 | if (f.default_value) |d| { | 47 | if (f.defaultValue()) |d| @field(res, f.name) = d; |
| 48 | @field(res, f.name) = @as(*const f.type, @alignCast(@ptrCast(d))).*; | ||
| 49 | } | ||
| 50 | } | 48 | } |
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | return res; | 51 | return res; |
| 54 | }, | 52 | }, |
| 55 | .Bool => { | 53 | .bool => { |
| 56 | const ele = try self.element(tag); | 54 | const ele = try self.element(tag); |
| 57 | const bytes = self.view(ele); | 55 | const bytes = self.view(ele); |
| 58 | if (bytes.len != 1) return error.InvalidBool; | 56 | if (bytes.len != 1) return error.InvalidBool; |
| ... | @@ -63,12 +61,12 @@ pub fn any(self: *Decoder, comptime T: type) !T { | ... | @@ -63,12 +61,12 @@ pub fn any(self: *Decoder, comptime T: type) !T { |
| 63 | else => error.InvalidBool, | 61 | else => error.InvalidBool, |
| 64 | }; | 62 | }; |
| 65 | }, | 63 | }, |
| 66 | .Int => { | 64 | .int => { |
| 67 | const ele = try self.element(tag); | 65 | const ele = try self.element(tag); |
| 68 | const bytes = self.view(ele); | 66 | const bytes = self.view(ele); |
| 69 | return try int(T, bytes); | 67 | return try int(T, bytes); |
| 70 | }, | 68 | }, |
| 71 | .Enum => |e| { | 69 | .@"enum" => |e| { |
| 72 | const ele = try self.element(tag); | 70 | const ele = try self.element(tag); |
| 73 | const bytes = self.view(ele); | 71 | const bytes = self.view(ele); |
| 74 | if (@hasDecl(T, "oids")) { | 72 | if (@hasDecl(T, "oids")) { |
| ... | @@ -76,7 +74,7 @@ pub fn any(self: *Decoder, comptime T: type) !T { | ... | @@ -76,7 +74,7 @@ pub fn any(self: *Decoder, comptime T: type) !T { |
| 76 | } | 74 | } |
| 77 | return @enumFromInt(try int(e.tag_type, bytes)); | 75 | return @enumFromInt(try int(e.tag_type, bytes)); |
| 78 | }, | 76 | }, |
| 79 | .Optional => |o| return self.any(o.child) catch return null, | 77 | .optional => |o| return self.any(o.child) catch return null, |
| 80 | else => @compileError("cannot decode type " ++ @typeName(T)), | 78 | else => @compileError("cannot decode type " ++ @typeName(T)), |
| 81 | } | 79 | } |
| 82 | } | 80 | } |
| ... | @@ -113,7 +111,7 @@ pub fn view(self: Decoder, elem: Element) []const u8 { | ... | @@ -113,7 +111,7 @@ pub fn view(self: Decoder, elem: Element) []const u8 { |
| 113 | } | 111 | } |
| 114 | 112 | ||
| 115 | fn int(comptime T: type, value: []const u8) error{ NonCanonical, LargeValue }!T { | 113 | 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"); |
| 117 | 115 | ||
| 118 | var bytes = value; | 116 | var bytes = value; |
| 119 | if (bytes.len >= 2) { | 117 | if (bytes.len >= 2) { |
lib/std/crypto/asn1/der/Encoder.zig+7-7| ... | @@ -28,7 +28,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { | ... | @@ -28,7 +28,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { |
| 28 | const merged_tag = self.mergedTag(tag_); | 28 | const merged_tag = self.mergedTag(tag_); |
| 29 | 29 | ||
| 30 | switch (@typeInfo(T)) { | 30 | switch (@typeInfo(T)) { |
| 31 | .Struct => |info| { | 31 | .@"struct" => |info| { |
| 32 | inline for (0..info.fields.len) |i| { | 32 | inline for (0..info.fields.len) |i| { |
| 33 | const f = info.fields[info.fields.len - i - 1]; | 33 | const f = info.fields[info.fields.len - i - 1]; |
| 34 | const field_val = @field(val, f.name); | 34 | const field_val = @field(val, f.name); |
| ... | @@ -36,7 +36,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { | ... | @@ -36,7 +36,7 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { |
| 36 | 36 | ||
| 37 | // > The encoding of a set value or sequence value shall not include an encoding for any | 37 | // > The encoding of a set value or sequence value shall not include an encoding for any |
| 38 | // > component value which is equal to its default value. | 38 | // > 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: { |
| 40 | const default_val: *const f.type = @alignCast(@ptrCast(v)); | 40 | const default_val: *const f.type = @alignCast(@ptrCast(v)); |
| 41 | break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val)); | 41 | break :brk std.mem.eql(u8, std.mem.asBytes(default_val), std.mem.asBytes(&field_val)); |
| 42 | } else false; | 42 | } else false; |
| ... | @@ -57,17 +57,17 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { | ... | @@ -57,17 +57,17 @@ fn anyTag(self: *Encoder, tag_: Tag, val: anytype) !void { |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | }, | 59 | }, |
| 60 | .Bool => try self.buffer.prependSlice(&[_]u8{if (val) 0xff else 0}), | 60 | .bool => try self.buffer.prependSlice(&[_]u8{if (val) 0xff else 0}), |
| 61 | .Int => try self.int(T, val), | 61 | .int => try self.int(T, val), |
| 62 | .Enum => |e| { | 62 | .@"enum" => |e| { |
| 63 | if (@hasDecl(T, "oids")) { | 63 | if (@hasDecl(T, "oids")) { |
| 64 | return self.any(T.oids.enumToOid(val)); | 64 | return self.any(T.oids.enumToOid(val)); |
| 65 | } else { | 65 | } else { |
| 66 | try self.int(e.tag_type, @intFromEnum(val)); | 66 | try self.int(e.tag_type, @intFromEnum(val)); |
| 67 | } | 67 | } |
| 68 | }, | 68 | }, |
| 69 | .Optional => if (val) |v| return try self.anyTag(tag_, v), | 69 | .optional => if (val) |v| return try self.anyTag(tag_, v), |
| 70 | .Null => {}, | 70 | .null => {}, |
| 71 | else => @compileError("cannot encode type " ++ @typeName(T)), | 71 | else => @compileError("cannot encode type " ++ @typeName(T)), |
| 72 | } | 72 | } |
| 73 | 73 |
lib/std/crypto/asn1/test.zig+4-4| ... | @@ -17,10 +17,10 @@ const AllTypes = struct { | ... | @@ -17,10 +17,10 @@ const AllTypes = struct { |
| 17 | h: asn1.Any, | 17 | h: asn1.Any, |
| 18 | 18 | ||
| 19 | pub const asn1_tags = .{ | 19 | pub const asn1_tags = .{ |
| 20 | .a = FieldTag.explicit(0, .context_specific), | 20 | .a = FieldTag.initExplicit(0, .context_specific), |
| 21 | .b = FieldTag.explicit(1, .context_specific), | 21 | .b = FieldTag.initExplicit(1, .context_specific), |
| 22 | .c = FieldTag.implicit(2, .context_specific), | 22 | .c = FieldTag.initImplicit(2, .context_specific), |
| 23 | .g = FieldTag.implicit(3, .context_specific), | 23 | .g = FieldTag.initImplicit(3, .context_specific), |
| 24 | }; | 24 | }; |
| 25 | 25 | ||
| 26 | const C = enum { | 26 | const C = enum { |