Skip to main content

DevicePublicKey

Struct DevicePublicKey 

Source
pub struct DevicePublicKey { /* private fields */ }
Expand description

A device public key carrying its curve type explicitly.

Curve is stored alongside the raw key bytes so dispatch never relies on key length — adding a new curve that shares a byte length (e.g. secp256k1, also 33 bytes compressed) won’t break existing match arms.

Accepted byte lengths per curve:

  • Ed25519: 32
  • P-256: 33 (compressed SEC1) or 65 (uncompressed SEC1)

Implementations§

Source§

impl DevicePublicKey

Source

pub fn try_new(curve: CurveType, bytes: &[u8]) -> Result<Self, InvalidKeyError>

Create from a curve type and raw bytes, validating length per curve.

Args:

  • curve: Which elliptic curve this key belongs to.
  • bytes: Raw public key bytes.

Usage:

let pk = DevicePublicKey::try_new(CurveType::Ed25519, &key_bytes)?;
Source

pub fn ed25519(bytes: &[u8; 32]) -> Self

Create an Ed25519 device key from raw 32-byte key.

Source

pub fn p256(bytes: &[u8]) -> Result<Self, InvalidKeyError>

Create a P-256 device key from raw SEC1 bytes (33 compressed or 65 uncompressed).

Returns Err if bytes is not 33 or 65 bytes.

Source

pub fn curve(&self) -> CurveType

Returns the curve type.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the raw key bytes.

Source

pub fn is_zero(&self) -> bool

Returns true if all bytes are zero.

Source

pub fn len(&self) -> usize

Returns the byte length.

Source

pub fn is_empty(&self) -> bool

Returns true if empty.

Source

pub async fn verify( &self, message: &[u8], signature: &[u8], provider: &dyn CryptoProvider, ) -> Result<(), SignatureVerifyError>

Verify a signature against this key, dispatching on curve.

This is the single canonical verify method — every caller that holds a DevicePublicKey should call this rather than branching on curve themselves. Adding a new curve means updating this one impl; the compiler then flags every call site still assuming only Ed25519.

Args:

  • message: Payload bytes that were signed.
  • signature: Raw signature bytes (64 for Ed25519 / P-256).
  • provider: Pluggable crypto provider (RingCryptoProvider native, WebCryptoProvider wasm) — used for Ed25519. P-256 routes through RingCryptoProvider::p256_verify on native.

Usage:

issuer_pk.verify(&payload, &signature, provider).await?;

Trait Implementations§

Source§

impl Clone for DevicePublicKey

Source§

fn clone(&self) -> DevicePublicKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DevicePublicKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DevicePublicKey

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DevicePublicKey

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for DevicePublicKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DevicePublicKey

Source§

impl From<Ed25519PublicKey> for DevicePublicKey

Source§

fn from(pk: Ed25519PublicKey) -> Self

Converts to this type from the input type.
Source§

impl Hash for DevicePublicKey

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DevicePublicKey

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for DevicePublicKey

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.