INNER CODE UNIT · Rust

generate

AChep/keyguard-app · commonAgent/src/lib.rs:62

    pub fn generate() -> Result<Self, IdentityError> {
        let mut bytes = [0u8; PRINCIPAL_FINGERPRINT_LEN];
        getrandom::fill(&mut bytes).map_err(IdentityError::Random)?;
        Ok(Self(bytes))
    }

    /// Constructs a principal from already validated opaque bytes.
    #[must_use]
    pub const fn from_bytes(bytes: [u8; PRINCIPAL_FINGERPRINT_LEN]) -> Self {
        Self(bytes)
    }

    /// Borrows the fixed-size principal bytes.
    #[must_use]
    pub const fn as_bytes(&self) -> &[u8; PRINCIPAL_FINGERPRINT_LEN] {
        &self.0
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…