Skip to main content

VCLPacket

Struct VCLPacket 

Source
pub struct VCLPacket {
    pub version: u8,
    pub packet_type: PacketType,
    pub sequence: u64,
    pub prev_hash: Vec<u8>,
    pub nonce: [u8; 24],
    pub payload: Vec<u8>,
    pub signature: Vec<u8>,
}
Expand description

A single unit of data transmission in VCL Protocol.

Packets are created, signed, and serialized internally by VCLConnection. After recv() returns, payload contains the decrypted data.

Fields§

§version: u8

Protocol version. Currently 2.

§packet_type: PacketType

Routing type — see PacketType.

§sequence: u64

Monotonically increasing sequence number (per direction).

§prev_hash: Vec<u8>

SHA-256 hash of the previous packet in the same direction. All-zeros for the first packet.

§nonce: [u8; 24]

24-byte XChaCha20 nonce used to encrypt this packet’s payload.

§payload: Vec<u8>

After recv(): decrypted payload. On the wire: XChaCha20-Poly1305 ciphertext.

§signature: Vec<u8>

64-byte Ed25519 signature over the packet hash.

Implementations§

Source§

impl VCLPacket

Source

pub fn new( sequence: u64, prev_hash: Vec<u8>, payload: Vec<u8>, nonce: [u8; 24], ) -> Self

Create a new PacketType::Data packet.

Source

pub fn new_typed( sequence: u64, prev_hash: Vec<u8>, payload: Vec<u8>, nonce: [u8; 24], packet_type: PacketType, ) -> Self

Create a packet with a specific PacketType. Used internally for Ping, Pong, KeyRotation, and Fragment packets.

Source

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

Compute the SHA-256 hash of this packet. Used for chain linking and signature generation.

Source

pub fn sign(&mut self, private_key: &[u8]) -> Result<(), VCLError>

Sign this packet with an Ed25519 private_key (32 bytes).

§Errors

Returns VCLError::InvalidKey if private_key is not 32 bytes.

Source

pub fn verify(&self, public_key: &[u8]) -> Result<bool, VCLError>

Verify the Ed25519 signature against public_key (32 bytes).

Returns Ok(true) if valid, Ok(false) if the signature does not match.

§Errors

Returns VCLError::InvalidKey if public_key is malformed.

Source

pub fn validate_chain(&self, expected_prev_hash: &[u8]) -> bool

Returns true if self.prev_hash matches expected_prev_hash.

Source

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

Serialize this packet to bytes using bincode.

Source

pub fn deserialize(data: &[u8]) -> Result<Self, VCLError>

Deserialize a packet from bytes.

§Errors

Returns VCLError::SerializationError if the bytes are malformed.

Trait Implementations§

Source§

impl Clone for VCLPacket

Source§

fn clone(&self) -> VCLPacket

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 VCLPacket

Source§

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

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

impl<'de> Deserialize<'de> for VCLPacket

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl Serialize for VCLPacket

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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