Skip to main content

rama_boring/
srtp.rs

1use crate::ffi;
2use crate::libc_types::c_ulong;
3use crate::stack::Stackable;
4use foreign_types::ForeignTypeRef;
5use std::ffi::CStr;
6use std::str;
7
8/// fake free method, since SRTP_PROTECTION_PROFILE is static
9unsafe fn free(_profile: *mut ffi::SRTP_PROTECTION_PROFILE) {}
10
11foreign_type_and_impl_send_sync! {
12    type CType = ffi::SRTP_PROTECTION_PROFILE;
13    fn drop = free;
14
15    pub struct SrtpProtectionProfile;
16}
17
18impl Stackable for SrtpProtectionProfile {
19    type StackType = ffi::stack_st_SRTP_PROTECTION_PROFILE;
20}
21
22impl SrtpProtectionProfileRef {
23    #[must_use]
24    pub fn id(&self) -> SrtpProfileId {
25        SrtpProfileId::from_raw(unsafe { (*self.as_ptr()).id })
26    }
27
28    #[must_use]
29    pub fn name(&self) -> &'static str {
30        unsafe { CStr::from_ptr((*self.as_ptr()).name.cast()) }
31            .to_str()
32            .expect("should be UTF-8")
33    }
34}
35
36/// An identifier of an SRTP protection profile.
37#[derive(Debug, Copy, Clone, PartialEq, Eq)]
38pub struct SrtpProfileId(c_ulong);
39
40impl SrtpProfileId {
41    pub const SRTP_AES128_CM_SHA1_80: SrtpProfileId =
42        SrtpProfileId(ffi::SRTP_AES128_CM_SHA1_80 as _);
43    pub const SRTP_AES128_CM_SHA1_32: SrtpProfileId =
44        SrtpProfileId(ffi::SRTP_AES128_CM_SHA1_32 as _);
45    pub const SRTP_AES128_F8_SHA1_80: SrtpProfileId =
46        SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_80 as _);
47    pub const SRTP_AES128_F8_SHA1_32: SrtpProfileId =
48        SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_32 as _);
49    pub const SRTP_NULL_SHA1_80: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_80 as _);
50    pub const SRTP_NULL_SHA1_32: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_32 as _);
51
52    /// Creates a `SrtpProfileId` from an integer representation.
53    #[must_use]
54    pub fn from_raw(value: c_ulong) -> SrtpProfileId {
55        SrtpProfileId(value)
56    }
57
58    /// Returns the integer representation of `SrtpProfileId`.
59    #[allow(clippy::trivially_copy_pass_by_ref)]
60    #[must_use]
61    pub fn as_raw(&self) -> c_ulong {
62        self.0
63    }
64}