diff options
| author | Frank Denis <124872+jedisct1@users.noreply.github.com> | 2025-02-06 16:37:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-06 16:37:42 +0100 |
| commit | b0ed602d5d9358128471588f00a073f2545809fa (patch) | |
| tree | e288247f700349e5d6089158ad1570aeaf9452b2 /lib/std/crypto/phc_encoding.zig | |
| parent | 1c07eacc7f26d2545d4c2149e3e3513875951370 (diff) | |
| download | zig-b0ed602d5d9358128471588f00a073f2545809fa.tar.gz zig-b0ed602d5d9358128471588f00a073f2545809fa.zip | |
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
Diffstat (limited to 'lib/std/crypto/phc_encoding.zig')
| -rw-r--r-- | lib/std/crypto/phc_encoding.zig | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/std/crypto/phc_encoding.zig b/lib/std/crypto/phc_encoding.zig index ee814861b3..507a02b983 100644 --- a/lib/std/crypto/phc_encoding.zig +++ b/lib/std/crypto/phc_encoding.zig @@ -75,6 +75,10 @@ pub fn BinValue(comptime max_len: usize) type { /// /// Other fields will also be deserialized from the function parameters section. pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult { + if (@hasField(HashResult, version_param_name)) { + @compileError("Field name '" ++ version_param_name ++ "'' is reserved for the algorithm version"); + } + var out = mem.zeroes(HashResult); var it = mem.splitScalar(u8, str, fields_delimiter_scalar); var set_fields: usize = 0; @@ -198,6 +202,11 @@ pub fn calcSize(params: anytype) usize { fn serializeTo(params: anytype, out: anytype) !void { const HashResult = @TypeOf(params); + + if (@hasField(HashResult, version_param_name)) { + @compileError("Field name '" ++ version_param_name ++ "'' is reserved for the algorithm version"); + } + try out.writeAll(fields_delimiter); try out.writeAll(params.alg_id); |
