Ed25519Extension

Struct Ed25519Extension 

Source
pub struct Ed25519Extension {
    pub ext_type: ExtensionType,
    pub type_int: u8,
    pub flags: Vec<ExtensionFlag>,
    pub flag_int: u8,
    pub data: Vec<u8>,
}
Expand description

An extension within an Ed25519 certificate.

Extensions provide additional data within a certificate. The most common extension type is ExtensionType::HasSigningKey, which embeds the public key used to sign the certificate.

§Structure

Each extension consists of:

  • A 2-byte length field (big-endian)
  • A 1-byte extension type
  • A 1-byte flags field
  • Variable-length data

§Flags

The flags field is a bitmask:

§Example

use stem_rs::descriptor::certificate::{Ed25519Extension, ExtensionType, ExtensionFlag};

// Create a signing key extension
let signing_key = vec![0u8; 32]; // 32-byte Ed25519 public key
let ext = Ed25519Extension::new(4, 0, signing_key).unwrap();

assert_eq!(ext.ext_type, ExtensionType::HasSigningKey);
assert!(ext.flags.is_empty()); // No flags set

Fields§

§ext_type: ExtensionType

The parsed extension type.

This is the semantic interpretation of type_int.

§type_int: u8

The raw integer value of the extension type.

Preserved for round-trip encoding of unknown extension types.

§flags: Vec<ExtensionFlag>

Flags associated with this extension.

See ExtensionFlag for the meaning of each flag.

§flag_int: u8

The raw integer value of the flags byte.

Preserved for round-trip encoding.

§data: Vec<u8>

The extension’s data payload.

For ExtensionType::HasSigningKey, this is a 32-byte Ed25519 public key.

Implementations§

Source§

impl Ed25519Extension

Source

pub fn new(ext_type: u8, flag_val: u8, data: Vec<u8>) -> Result<Self, Error>

Creates a new Ed25519 certificate extension.

§Arguments
  • ext_type - The extension type as an integer
  • flag_val - The flags byte
  • data - The extension’s data payload
§Returns

A new Ed25519Extension on success.

§Errors

Returns Error::Parse if:

§Example
use stem_rs::descriptor::certificate::Ed25519Extension;

// Create a signing key extension (type 4)
let key_data = vec![0u8; 32];
let ext = Ed25519Extension::new(4, 0, key_data).unwrap();

// Invalid: signing key must be 32 bytes
let result = Ed25519Extension::new(4, 0, vec![0u8; 16]);
assert!(result.is_err());
Source

pub fn pack(&self) -> Vec<u8>

Encodes this extension to its binary representation.

The encoded format is:

  • 2 bytes: data length (big-endian)
  • 1 byte: extension type
  • 1 byte: flags
  • N bytes: data
§Returns

A byte vector containing the encoded extension.

§Example
use stem_rs::descriptor::certificate::Ed25519Extension;

let ext = Ed25519Extension::new(4, 0, vec![0u8; 32]).unwrap();
let packed = ext.pack();

// 2 (length) + 1 (type) + 1 (flags) + 32 (data) = 36 bytes
assert_eq!(packed.len(), 36);
Source

pub fn pop(content: &[u8]) -> Result<(Self, &[u8]), Error>

Parses an extension from the beginning of a byte slice.

This method reads one extension from the input and returns both the parsed extension and the remaining unparsed bytes.

§Arguments
  • content - The byte slice to parse from
§Returns

A tuple of (parsed extension, remaining bytes) on success.

§Errors

Returns Error::Parse if:

  • The input is too short to contain the extension header (< 4 bytes)
  • The input is truncated (data length exceeds available bytes)
  • The extension data is invalid (e.g., wrong size for signing key)
§Example
use stem_rs::descriptor::certificate::Ed25519Extension;

// Extension: length=2, type=5, flags=0, data=[0x11, 0x22]
let data = [0x00, 0x02, 0x05, 0x00, 0x11, 0x22, 0xFF];
let (ext, remaining) = Ed25519Extension::pop(&data).unwrap();

assert_eq!(ext.type_int, 5);
assert_eq!(ext.data, vec![0x11, 0x22]);
assert_eq!(remaining, &[0xFF]); // Remaining byte

Trait Implementations§

Source§

impl Clone for Ed25519Extension

Source§

fn clone(&self) -> Ed25519Extension

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Ed25519Extension

Source§

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

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

impl PartialEq for Ed25519Extension

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for Ed25519Extension

Source§

impl StructuralPartialEq for Ed25519Extension

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> 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, 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.