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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Input wrapper for transform operations.
/// Input data that can be transformed into a private key.
///
/// Contains multiple representations of the same value for different transforms.
#[derive(Clone)]
pub struct Input {
/// Original u64 value (for range sources)
pub u64_val: Option<u64>,
/// String representation
pub string_val: String,
/// Big-endian bytes (8 bytes)
pub bytes_be: Option<[u8; 8]>,
/// Little-endian bytes (8 bytes)
pub bytes_le: Option<[u8; 8]>,
/// Arbitrary binary data (for file-based transforms like bitimage)
pub blob: Option<Vec<u8>>,
}
impl Input {
/// Create input from a u64 value
pub fn from_u64(val: u64) -> Self {
Self {
u64_val: Some(val),
string_val: val.to_string(),
bytes_be: Some(val.to_be_bytes()),
bytes_le: Some(val.to_le_bytes()),
blob: None,
}
}
/// Create input from a string (passphrase)
pub fn from_string(s: String) -> Self {
Self {
u64_val: None,
string_val: s,
bytes_be: None,
bytes_le: None,
blob: None,
}
}
/// Create input from arbitrary bytes (for file-based transforms)
///
/// # Arguments
/// * `data` - The binary data (e.g., file contents)
/// * `label` - Human-readable source description (e.g., file path)
pub fn from_blob(data: Vec<u8>, label: String) -> Self {
Self {
u64_val: None,
string_val: label,
bytes_be: None,
bytes_le: None,
blob: Some(data),
}
}
}