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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use core::fmt;
use hex;
use optee_teec_sys as raw;
use uuid as uuid_crate;
use uuid_crate::parser::ParseError;
use uuid_crate::BytesError;
pub struct Uuid {
raw: raw::TEEC_UUID,
}
impl Uuid {
pub fn parse_str(input: &str) -> Result<Uuid, ParseError> {
let uuid = uuid_crate::Uuid::parse_str(input)?;
let (time_low, time_mid, time_hi_and_version, clock_seq_and_node) = uuid.as_fields();
Ok(Self::new_raw(
time_low,
time_mid,
time_hi_and_version,
*clock_seq_and_node,
))
}
pub fn from_bytes(bytes: [u8; 16]) -> Uuid {
let uuid = uuid_crate::Uuid::from_bytes(bytes);
let (time_low, time_mid, time_hi_and_version, clock_seq_and_node) = uuid.as_fields();
Self::new_raw(time_low, time_mid, time_hi_and_version, *clock_seq_and_node)
}
pub fn from_slice(b: &[u8]) -> Result<Uuid, BytesError> {
let uuid = uuid_crate::Uuid::from_slice(b)?;
let (time_low, time_mid, time_hi_and_version, clock_seq_and_node) = uuid.as_fields();
Ok(Self::new_raw(
time_low,
time_mid,
time_hi_and_version,
*clock_seq_and_node,
))
}
pub fn new_raw(
time_low: u32,
time_mid: u16,
time_hi_and_version: u16,
clock_seq_and_nod: [u8; 8],
) -> Uuid {
let raw_uuid = raw::TEEC_UUID {
timeLow: time_low,
timeMid: time_mid,
timeHiAndVersion: time_hi_and_version,
clockSeqAndNode: clock_seq_and_nod,
};
Self { raw: raw_uuid }
}
pub fn as_raw_ptr(&self) -> *const raw::TEEC_UUID {
&self.raw
}
}
impl fmt::Display for Uuid {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{:x}-{:x}-{:x}-{}",
self.raw.timeLow,
self.raw.timeMid,
self.raw.timeHiAndVersion,
hex::encode(self.raw.clockSeqAndNode)
)
}
}