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 foreign_type_and_impl_send_sync! {
11     type CType = ffi::SRTP_PROTECTION_PROFILE;
12     fn drop = free;
13 
14     pub struct SrtpProtectionProfile;
15     /// Reference to `SrtpProtectionProfile`.
16     pub struct SrtpProtectionProfileRef;
17 }
18 
19 impl Stackable for SrtpProtectionProfile {
20     type StackType = ffi::stack_st_SRTP_PROTECTION_PROFILE;
21 }
22 
23 impl SrtpProtectionProfileRef {
id(&self) -> SrtpProfileId24     pub fn id(&self) -> SrtpProfileId {
25         SrtpProfileId::from_raw(unsafe { (*self.as_ptr()).id })
26     }
name(&self) -> &'static str27     pub fn name(&self) -> &'static str {
28         unsafe { CStr::from_ptr((*self.as_ptr()).name as *const _) }
29             .to_str()
30             .expect("should be UTF-8")
31     }
32 }
33 
34 /// An identifier of an SRTP protection profile.
35 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
36 pub struct SrtpProfileId(c_ulong);
37 
38 impl SrtpProfileId {
39     pub const SRTP_AES128_CM_SHA1_80: SrtpProfileId = SrtpProfileId(ffi::SRTP_AES128_CM_SHA1_80);
40     pub const SRTP_AES128_CM_SHA1_32: SrtpProfileId = SrtpProfileId(ffi::SRTP_AES128_CM_SHA1_32);
41     pub const SRTP_AES128_F8_SHA1_80: SrtpProfileId = SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_80);
42     pub const SRTP_AES128_F8_SHA1_32: SrtpProfileId = SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_32);
43     pub const SRTP_NULL_SHA1_80: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_80);
44     pub const SRTP_NULL_SHA1_32: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_32);
45     #[cfg(ossl110)]
46     pub const SRTP_AEAD_AES_128_GCM: SrtpProfileId = SrtpProfileId(ffi::SRTP_AEAD_AES_128_GCM);
47     #[cfg(ossl110)]
48     pub const SRTP_AEAD_AES_256_GCM: SrtpProfileId = SrtpProfileId(ffi::SRTP_AEAD_AES_256_GCM);
49 
50     /// Creates a `SrtpProfileId` from an integer representation.
from_raw(value: c_ulong) -> SrtpProfileId51     pub fn from_raw(value: c_ulong) -> SrtpProfileId {
52         SrtpProfileId(value)
53     }
54 
55     /// Returns the integer representation of `SrtpProfileId`.
56     #[allow(clippy::trivially_copy_pass_by_ref)]
as_raw(&self) -> c_ulong57     pub fn as_raw(&self) -> c_ulong {
58         self.0
59     }
60 }
61