1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// This file is part of helpers4.
// Copyright (C) 2025 baxyz
// SPDX-License-Identifier: LGPL-3.0-or-later
use decode_to_slice;
use DecodeError;
/// Decodes a hexadecimal string into a fixed-size array, e.g. a 32-byte key from 64 hex digits.
///
/// # Arguments
///
/// - `hex` - The hexadecimal string to decode; must encode exactly `N` bytes.
///
/// # Errors
///
/// Same as [`decode_to_slice`](super::decode_to_slice): the string must have exactly `2 * N`
/// hex digits.
///
/// # Examples
///
/// ```
/// use helpers4::hex::decode_array;
///
/// let key: [u8; 4] = decode_array("deadbeef")?;
/// assert_eq!(key, [0xde, 0xad, 0xbe, 0xef]);
/// assert!(decode_array::<4>("dead").is_err());
/// # Ok::<(), helpers4::hex::DecodeError>(())
/// ```