Trait PtpPacket

Source
pub trait PtpPacket<HT, BT>{
    // Required methods
    fn get_header(&self) -> &HT;
    fn get_body(&self) -> &BT;
    fn get_mac(&self) -> Option<&[u8; 16]>;
    fn new(header: HT, body: BT, mac: Option<[u8; 16]>) -> Self;

    // Provided methods
    fn from_bytes(
        data: &[u8],
        info: SerializationInfo,
    ) -> Result<Self, SerializationError>
       where Self: Sized { ... }
    fn get_bytes(
        &self,
        info: SerializationInfo,
        with_len: bool,
    ) -> Result<Vec<u8>, SerializationError> { ... }
    fn verify_mac(&self, key: &[u8; 32], bucket_key: Option<[u8; 32]>) -> bool { ... }
}

Required Methods§

Source

fn get_header(&self) -> &HT

Returns the header of the packet

Source

fn get_body(&self) -> &BT

Returns the body of the packet

Source

fn get_mac(&self) -> Option<&[u8; 16]>

Returns the MAC of the packet (if present)

Source

fn new(header: HT, body: BT, mac: Option<[u8; 16]>) -> Self

Create a new packet with the given header, body and MAC

Provided Methods§

Source

fn from_bytes( data: &[u8], info: SerializationInfo, ) -> Result<Self, SerializationError>
where Self: Sized,

Deserialize packet from bytes

§Arguments
  • data - The bytes to deserialize
  • info - The info to use for deserialization
§Errors
  • SerializationError::DecryptionFailed - If the packet is encrypted and the decryption fails
  • SerializationError::MissingInfo - If the packet is encrypted or authenticated and the info is missing
  • SerializationError::AuthenticationFailed - If the packet is authenticated and the authentication fails
§Returns

The deserialized packet or an error

Source

fn get_bytes( &self, info: SerializationInfo, with_len: bool, ) -> Result<Vec<u8>, SerializationError>

Serialize packet to bytes

§Arguments
  • info - The info to use for serialization
  • with_len - Whether to prepend the length of the packet (plabble dyn_int bytes)
§Errors
  • SerializationError::MissingInfo - No serialization info is provided
Source

fn verify_mac(&self, key: &[u8; 32], bucket_key: Option<[u8; 32]>) -> bool

Verifies the MAC of the packet This method is needed so a non-encrypted packet can be checked after deserialization if we do not want to “peek” the header, which is less efficient

§Arguments
  • key - The key to verify the MAC with. Must be generated with HKDF
  • bucket_key - The bucket key to add to the auth_data if authentication is needed. Optional

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§