MCPcopy Create free account
hub / github.com/RustCrypto/utils / decode

Function decode

hex-literal/src/lib.rs:61–77  ·  view source on GitHub ↗
(strings: &[&[u8]])

Source from the content-addressed store, hash-verified

59#[doc(hidden)]
60#[must_use]
61pub const fn decode<const LEN: usize>(strings: &[&[u8]]) -> Option<[u8; LEN]> {
62 let mut string_pos = 0;
63 let mut buf = [0u8; LEN];
64 let mut buf_pos = 0;
65 while string_pos < strings.len() {
66 let mut pos = 0;
67 let string = &strings[string_pos];
68 string_pos += 1;
69
70 while let Some((byte, new_pos)) = next_byte(string, pos) {
71 buf[buf_pos] = byte;
72 buf_pos += 1;
73 pos = new_pos;
74 }
75 }
76 if LEN == buf_pos { Some(buf) } else { None }
77}
78
79/// Converts a sequence of hexadecimal string literals to a byte array at compile time.
80///

Callers 1

deserializeFunction · 0.50

Calls 2

next_byteFunction · 0.85
lenMethod · 0.80

Tested by

no test coverage detected