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 |
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 { |
24 | pub fn id(&self) -> SrtpProfileId { |
25 | SrtpProfileId::from_raw(unsafe { (*self.as_ptr()).id }) |
26 | } |
27 | pub fn name(&self) -> &'static str { |
28 | unsafe { CStr::from_ptr((*self.as_ptr()).name as *const _) } |
29 | .to_str() |
30 | .expect(msg:"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 = |
40 | SrtpProfileId(ffi::SRTP_AES128_CM_SHA1_80 as c_ulong); |
41 | pub const SRTP_AES128_CM_SHA1_32: SrtpProfileId = |
42 | SrtpProfileId(ffi::SRTP_AES128_CM_SHA1_32 as c_ulong); |
43 | pub const SRTP_AES128_F8_SHA1_80: SrtpProfileId = |
44 | SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_80 as c_ulong); |
45 | pub const SRTP_AES128_F8_SHA1_32: SrtpProfileId = |
46 | SrtpProfileId(ffi::SRTP_AES128_F8_SHA1_32 as c_ulong); |
47 | pub const SRTP_NULL_SHA1_80: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_80 as c_ulong); |
48 | pub const SRTP_NULL_SHA1_32: SrtpProfileId = SrtpProfileId(ffi::SRTP_NULL_SHA1_32 as c_ulong); |
49 | #[cfg (any(boringssl, ossl110))] |
50 | pub const SRTP_AEAD_AES_128_GCM: SrtpProfileId = |
51 | SrtpProfileId(ffi::SRTP_AEAD_AES_128_GCM as c_ulong); |
52 | #[cfg (any(boringssl, ossl110))] |
53 | pub const SRTP_AEAD_AES_256_GCM: SrtpProfileId = |
54 | SrtpProfileId(ffi::SRTP_AEAD_AES_256_GCM as c_ulong); |
55 | |
56 | /// Creates a `SrtpProfileId` from an integer representation. |
57 | pub fn from_raw(value: c_ulong) -> SrtpProfileId { |
58 | SrtpProfileId(value) |
59 | } |
60 | |
61 | /// Returns the integer representation of `SrtpProfileId`. |
62 | #[allow (clippy::trivially_copy_pass_by_ref)] |
63 | pub fn as_raw(&self) -> c_ulong { |
64 | self.0 |
65 | } |
66 | } |
67 | |