Skip to main content

harmos_sidecar/kit/
identity.rs

1/* ***
2 *
3 * Harmos
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * ***
8 */
9
10/* === Modules === */
11
12/* === Re-Exports === */
13
14/* === Imports === */
15
16// Standard Library Imports
17use std::{fmt, io};
18// Third Party Imports
19
20// Local Imports
21
22/* === Constants === */
23
24/* === Macros === */
25
26/* === Type Aliases === */
27
28/* === Structs === */
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
31pub struct ActivationId([u8; 16]);
32
33#[derive(Clone, Copy)]
34pub(super) struct Identity {
35    pub(super) observer: &'static str,
36    pub(super) activation: ActivationId,
37}
38
39/* === Enums === */
40
41/* === Traits === */
42
43/* === Implementations === */
44
45impl Identity {
46    pub(super) fn new(observer: &'static str) -> io::Result<Self> {
47        let mut bytes = [0; 16];
48        getrandom::fill(&mut bytes)?;
49        Ok(Self {
50            observer,
51            activation: ActivationId(bytes),
52        })
53    }
54}
55
56impl fmt::Display for ActivationId {
57    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
58        for byte in self.0 {
59            write!(formatter, "{byte:02x}")?;
60        }
61        Ok(())
62    }
63}
64
65/* === Public Functions === */
66
67/* === Private Functions === */
68
69/* === Tests === */