use std::fmt;
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct IvParts {
pub ssrc: u32,
pub rtp_timestamp: u32,
pub send_count: u32,
}
impl fmt::Debug for IvParts {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("IvParts(..)")
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum SealError {
#[error("frame too short")]
FrameTooShort,
#[error("slot outside the key ring")]
BadSlot,
#[error("cipher failure")]
Cipher,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum OpenError {
#[error("malformed trailer")]
BadTrailer,
#[error("no key at index {0}")]
NoKey(u8),
#[error("tag did not verify at index {0}")]
BadTag(u8),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum VideoFrameCodec {
Vp8,
H264,
}
pub trait FrameCrypto: Send + Sync + 'static {
type Key: Send + Sync + fmt::Debug;
fn derive(&self, ikm: &[u8; 32]) -> Self::Key;
fn seal(
&self,
key: &Self::Key,
slot: u8,
iv: IvParts,
frame: &[u8],
out: &mut Vec<u8>,
) -> Result<(), SealError>;
fn seal_video(
&self,
key: &Self::Key,
slot: u8,
codec: VideoFrameCodec,
iv: IvParts,
frame: &[u8],
out: &mut Vec<u8>,
) -> Result<(), SealError> {
let _ = (key, slot, codec, iv, frame, out);
Err(SealError::Cipher)
}
fn key_index(&self, frame: &[u8]) -> Result<u8, OpenError>;
fn open(&self, key: &Self::Key, frame: &[u8], out: &mut Vec<u8>) -> Result<(), OpenError>;
fn open_video(
&self,
key: &Self::Key,
codec: crate::video::VideoCodec,
frame: &[u8],
out: &mut Vec<u8>,
) -> Result<(), OpenError> {
let _ = (key, codec, frame, out);
Err(OpenError::BadTrailer)
}
}