authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2025-02-06 16:37:42+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-02-06 16:37:42+01:00
logb0ed602d5d9358128471588f00a073f2545809fa
treee288247f700349e5d6089158ad1570aeaf9452b2
parent1c07eacc7f26d2545d4c2149e3e3513875951370
signaturebadge-check Signed by PGP key B5690EEEBB952194

crypto/phc-encoding: forbid parameters named 'v' (#22569)

The spec is ambiguous, and it's too late to change it. So the most reasonable thing to do in order to avoid generating strings that could be parsed differently by other implementations is to forbid parameters named "v" at compile-time. See https://github.com/P-H-C/phc-string-format/issues/8

1 files changed, 9 insertions(+), 0 deletions(-)

lib/std/crypto/phc_encoding.zig+9
...@@ -75,6 +75,10 @@ pub fn BinValue(comptime max_len: usize) type {...@@ -75,6 +75,10 @@ pub fn BinValue(comptime max_len: usize) type {
75///75///
76/// Other fields will also be deserialized from the function parameters section.76/// Other fields will also be deserialized from the function parameters section.
77pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult {77pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult {
78 if (@hasField(HashResult, version_param_name)) {
79 @compileError("Field name '" ++ version_param_name ++ "'' is reserved for the algorithm version");
80 }
81
78 var out = mem.zeroes(HashResult);82 var out = mem.zeroes(HashResult);
79 var it = mem.splitScalar(u8, str, fields_delimiter_scalar);83 var it = mem.splitScalar(u8, str, fields_delimiter_scalar);
80 var set_fields: usize = 0;84 var set_fields: usize = 0;
...@@ -198,6 +202,11 @@ pub fn calcSize(params: anytype) usize {...@@ -198,6 +202,11 @@ pub fn calcSize(params: anytype) usize {
198202
199fn serializeTo(params: anytype, out: anytype) !void {203fn serializeTo(params: anytype, out: anytype) !void {
200 const HashResult = @TypeOf(params);204 const HashResult = @TypeOf(params);
205
206 if (@hasField(HashResult, version_param_name)) {
207 @compileError("Field name '" ++ version_param_name ++ "'' is reserved for the algorithm version");
208 }
209
201 try out.writeAll(fields_delimiter);210 try out.writeAll(fields_delimiter);
202 try out.writeAll(params.alg_id);211 try out.writeAll(params.alg_id);
203212