1 #![warn(rust_2018_idioms)] 2 #![allow(dead_code)] 3 4 use async_trait::async_trait; 5 use thiserror::Error; 6 7 use std::io; 8 9 #[cfg(feature = "vnet")] 10 #[macro_use] 11 extern crate lazy_static; 12 13 #[cfg(target_family = "windows")] 14 #[macro_use] 15 extern crate bitflags; 16 17 pub mod fixed_big_int; 18 pub mod replay_detector; 19 20 /// KeyingMaterialExporter to extract keying material. 21 /// 22 /// This trait sits here to avoid getting a direct dependency between 23 /// the dtls and srtp crates. 24 #[async_trait] 25 pub trait KeyingMaterialExporter { export_keying_material( &self, label: &str, context: &[u8], length: usize, ) -> std::result::Result<Vec<u8>, KeyingMaterialExporterError>26 async fn export_keying_material( 27 &self, 28 label: &str, 29 context: &[u8], 30 length: usize, 31 ) -> std::result::Result<Vec<u8>, KeyingMaterialExporterError>; 32 } 33 34 /// Possible errors while exporting keying material. 35 /// 36 /// These errors might have been more logically kept in the dtls 37 /// crate, but that would have required a direct depdency between 38 /// srtp and dtls. 39 #[derive(Debug, Error, PartialEq)] 40 #[non_exhaustive] 41 pub enum KeyingMaterialExporterError { 42 #[error("tls handshake is in progress")] 43 HandshakeInProgress, 44 #[error("context is not supported for export_keying_material")] 45 ContextUnsupported, 46 #[error("export_keying_material can not be used with a reserved label")] 47 ReservedExportKeyingMaterial, 48 #[error("no cipher suite for export_keying_material")] 49 CipherSuiteUnset, 50 #[error("export_keying_material io: {0}")] 51 Io(#[source] error::IoError), 52 #[error("export_keying_material hash: {0}")] 53 Hash(String), 54 } 55 56 impl From<io::Error> for KeyingMaterialExporterError { from(e: io::Error) -> Self57 fn from(e: io::Error) -> Self { 58 KeyingMaterialExporterError::Io(error::IoError(e)) 59 } 60 } 61 62 #[cfg(feature = "buffer")] 63 pub mod buffer; 64 65 #[cfg(feature = "conn")] 66 pub mod conn; 67 68 #[cfg(feature = "ifaces")] 69 pub mod ifaces; 70 71 #[cfg(feature = "vnet")] 72 pub mod vnet; 73 74 #[cfg(feature = "marshal")] 75 pub mod marshal; 76 77 #[cfg(feature = "buffer")] 78 pub use crate::buffer::Buffer; 79 80 #[cfg(feature = "conn")] 81 pub use crate::conn::Conn; 82 83 #[cfg(feature = "marshal")] 84 pub use crate::marshal::{exact_size_buf::ExactSizeBuf, Marshal, MarshalSize, Unmarshal}; 85 86 mod error; 87 pub use error::{Error, Result}; 88 89 #[cfg(feature = "sync")] 90 pub mod sync; 91