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