decode
Decodes a hexadecimal string into a binary buffer. The output buffer must be half the size of the input buffer.
Function parameters
Parameters
- bin:[]u8
- encoded:[]const u8
(best-effort) constant time hexadecimal encoding and decoding.
Types
Error sets in this namespace
Error Sets
Source
Implementation
pub fn decode(bin: []u8, encoded: []const u8) error{ SizeMismatch, InvalidCharacter, InvalidPadding }!void {
if (encoded.len % 2 != 0) {
return error.InvalidPadding;
}
if (bin.len < encoded.len / 2) {
return error.SizeMismatch;
}
_ = decodeAny(bin, encoded, null) catch |err| {
switch (err) {
error.InvalidCharacter => return error.InvalidCharacter,
error.InvalidPadding => return error.InvalidPadding,
else => unreachable,
}
};
}