pub struct DeviceId(/* private fields */);Expand description
Device identifier derived from Ed25519 public key.
The DeviceId is the first 16 bytes of SHA-256(public_key), providing:
- Uniqueness guarantee from the cryptographic hash
- Compact representation (32 hex chars instead of 64)
- Collision resistance from SHA-256
§Example
ⓘ
use peat_mesh::security::{DeviceKeypair, DeviceId};
let keypair = DeviceKeypair::generate();
let device_id = keypair.device_id();
// Convert to hex string for display/serialization
let hex = device_id.to_hex();
// Parse back from hex
let parsed = DeviceId::from_hex(&hex)?;
assert_eq!(device_id, parsed);Implementations§
Source§impl DeviceId
impl DeviceId
Sourcepub fn from_public_key(public_key: &VerifyingKey) -> Self
pub fn from_public_key(public_key: &VerifyingKey) -> Self
Create a DeviceId from an Ed25519 public key.
The ID is computed as SHA-256(public_key)[0..16].
Sourcepub fn from_public_key_bytes(bytes: &[u8]) -> Result<Self, SecurityError>
pub fn from_public_key_bytes(bytes: &[u8]) -> Result<Self, SecurityError>
Create a DeviceId from raw public key bytes (32 bytes).
Sourcepub fn from_bytes(bytes: [u8; 16]) -> Self
pub fn from_bytes(bytes: [u8; 16]) -> Self
Create a DeviceId from raw bytes (16 bytes).
Sourcepub fn from_hex(hex: &str) -> Result<Self, SecurityError>
pub fn from_hex(hex: &str) -> Result<Self, SecurityError>
Parse from a hex string (32 characters).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DeviceId
impl<'de> Deserialize<'de> for DeviceId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for DeviceId
impl Eq for DeviceId
impl StructuralPartialEq for DeviceId
Auto Trait Implementations§
impl Freeze for DeviceId
impl RefUnwindSafe for DeviceId
impl Send for DeviceId
impl Sync for DeviceId
impl Unpin for DeviceId
impl UnsafeUnpin for DeviceId
impl UnwindSafe for DeviceId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.