1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use MIKEYCacheType;
use MIKEYMapType;
use MIKEYPRFFunc;
use MIKEYPayload;
use MIKEYPayloadType;
use MIKEYType;
use ffi;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use gst;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// Structure holding the information of the MIKEY message
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct MIKEYMessage(Boxed<ffi::GstMIKEYMessage>);

    match fn {
        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::gst_mikey_message_get_type(), ptr as *mut _) as *mut ffi::GstMIKEYMessage,
        free => |ptr| gobject_ffi::g_boxed_free(ffi::gst_mikey_message_get_type(), ptr as *mut _),
        get_type => || ffi::gst_mikey_message_get_type(),
    }
}

impl MIKEYMessage {
    /// Make a new MIKEY message.
    ///
    /// # Returns
    ///
    /// a new `MIKEYMessage` on success
    pub fn new() -> MIKEYMessage {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_mikey_message_new())
        }
    }

    //pub fn new_from_bytes(bytes: &glib::Bytes, info: /*Ignored*/&mut MIKEYDecryptInfo, error: /*Ignored*/Option<Error>) -> MIKEYMessage {
    //    unsafe { TODO: call ffi::gst_mikey_message_new_from_bytes() }
    //}

    /// Makes mikey message including:
    ///  - Security Policy Payload
    ///  - Key Data Transport Payload
    ///  - Key Data Sub-Payload
    /// ## `caps`
    /// a `gst::Caps`, including SRTP parameters (srtp/srtcp cipher, authorization, key data)
    ///
    /// # Returns
    ///
    /// a `MIKEYMessage`,
    /// or `None` if there is no srtp information in the caps.
    pub fn new_from_caps(caps: &gst::Caps) -> MIKEYMessage {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gst_mikey_message_new_from_caps(caps.to_glib_none().0))
        }
    }

    //pub fn new_from_data(data: &[u8], info: /*Ignored*/&mut MIKEYDecryptInfo, error: /*Ignored*/Option<Error>) -> MIKEYMessage {
    //    unsafe { TODO: call ffi::gst_mikey_message_new_from_data() }
    //}

    /// Add a Crypto policy for SRTP to `self`.
    /// ## `policy`
    /// The security policy applied for the stream with `ssrc`
    /// ## `ssrc`
    /// the SSRC that must be used for the stream
    /// ## `roc`
    /// current rollover counter
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn add_cs_srtp(&mut self, policy: u8, ssrc: u32, roc: u32) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_add_cs_srtp(self.to_glib_none_mut().0, policy, ssrc, roc))
        }
    }

    /// Add a new PKE payload to `self` with the given parameters.
    /// ## `C`
    /// envelope key cache indicator
    /// ## `data_len`
    /// the length of `data`
    /// ## `data`
    /// the encrypted envelope key
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn add_pke(&mut self, C: MIKEYCacheType, data: &[u8]) -> bool {
        let data_len = data.len() as u16;
        unsafe {
            from_glib(ffi::gst_mikey_message_add_pke(self.to_glib_none_mut().0, C.to_glib(), data_len, data.to_glib_none().0))
        }
    }

    /// Add a new RAND payload to `self` with the given parameters.
    /// ## `len`
    /// the length of `rand`
    /// ## `rand`
    /// random data
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn add_rand(&mut self, rand: &[u8]) -> bool {
        let len = rand.len() as u8;
        unsafe {
            from_glib(ffi::gst_mikey_message_add_rand(self.to_glib_none_mut().0, len, rand.to_glib_none().0))
        }
    }

    /// Add a new RAND payload to `self` with `len` random bytes.
    /// ## `len`
    /// length
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn add_rand_len(&mut self, len: u8) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_add_rand_len(self.to_glib_none_mut().0, len))
        }
    }

    //pub fn add_t(&mut self, type_: MIKEYTSType, ts_value: &[u8]) -> bool {
    //    unsafe { TODO: call ffi::gst_mikey_message_add_t() }
    //}

    /// Add a new T payload to `self` that contains the current time
    /// in NTP-UTC format.
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn add_t_now_ntp_utc(&mut self) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_add_t_now_ntp_utc(self.to_glib_none_mut().0))
        }
    }

    /// Find the `nth` occurence of the payload with `type_` in `self`.
    /// ## `type_`
    /// a `MIKEYPayloadType`
    /// ## `nth`
    /// payload to find
    ///
    /// # Returns
    ///
    /// the `nth` `MIKEYPayload` of `type_`.
    pub fn find_payload(&self, type_: MIKEYPayloadType, nth: u32) -> Option<MIKEYPayload> {
        unsafe {
            from_glib_none(ffi::gst_mikey_message_find_payload(self.to_glib_none().0, type_.to_glib(), nth))
        }
    }

    //pub fn get_cs_srtp(&self, idx: u32) -> /*Ignored*/Option<MIKEYMapSRTP> {
    //    unsafe { TODO: call ffi::gst_mikey_message_get_cs_srtp() }
    //}

    /// Get the number of crypto sessions in `self`.
    ///
    /// # Returns
    ///
    /// the number of crypto sessions
    pub fn get_n_cs(&self) -> u32 {
        unsafe {
            ffi::gst_mikey_message_get_n_cs(self.to_glib_none().0)
        }
    }

    /// Get the number of payloads in `self`.
    ///
    /// # Returns
    ///
    /// the number of payloads in `self`
    pub fn get_n_payloads(&self) -> u32 {
        unsafe {
            ffi::gst_mikey_message_get_n_payloads(self.to_glib_none().0)
        }
    }

    //pub fn insert_cs_srtp(&mut self, idx: i32, map: /*Ignored*/&MIKEYMapSRTP) -> bool {
    //    unsafe { TODO: call ffi::gst_mikey_message_insert_cs_srtp() }
    //}

    /// Remove the SRTP policy at `idx`.
    /// ## `idx`
    /// the index to remove
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn remove_cs_srtp(&mut self, idx: i32) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_remove_cs_srtp(self.to_glib_none_mut().0, idx))
        }
    }

    /// Remove the payload in `self` at `idx`
    /// ## `idx`
    /// an index
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn remove_payload(&mut self, idx: u32) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_remove_payload(self.to_glib_none_mut().0, idx))
        }
    }

    //pub fn replace_cs_srtp(&mut self, idx: i32, map: /*Ignored*/&MIKEYMapSRTP) -> bool {
    //    unsafe { TODO: call ffi::gst_mikey_message_replace_cs_srtp() }
    //}

    /// Set the information in `self`.
    /// ## `version`
    /// a version
    /// ## `type_`
    /// a `MIKEYType`
    /// ## `V`
    /// verify flag
    /// ## `prf_func`
    /// the `MIKEYPRFFunc` function to use
    /// ## `CSB_id`
    /// the Crypto Session Bundle id
    /// ## `map_type`
    /// the `GstMIKEYCSIDMapType`
    ///
    /// # Returns
    ///
    /// `true` on success
    pub fn set_info(&mut self, version: u8, type_: MIKEYType, V: bool, prf_func: MIKEYPRFFunc, CSB_id: u32, map_type: MIKEYMapType) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_set_info(self.to_glib_none_mut().0, version, type_.to_glib(), V.to_glib(), prf_func.to_glib(), CSB_id, map_type.to_glib()))
        }
    }

    //pub fn to_bytes(&mut self, info: /*Ignored*/&mut MIKEYEncryptInfo, error: /*Ignored*/Option<Error>) -> Option<glib::Bytes> {
    //    unsafe { TODO: call ffi::gst_mikey_message_to_bytes() }
    //}

    ///
    /// Feature: `v1_8_1`
    ///
    /// ## `caps`
    /// a `gst::Caps` to be filled with SRTP parameters (srtp/srtcp cipher, authorization, key data)
    ///
    /// # Returns
    ///
    /// `true` on success
    #[cfg(any(feature = "v1_8_1", feature = "dox"))]
    pub fn to_caps(&self, caps: &gst::Caps) -> bool {
        unsafe {
            from_glib(ffi::gst_mikey_message_to_caps(self.to_glib_none().0, caps.to_glib_none().0))
        }
    }
}

impl Default for MIKEYMessage {
    fn default() -> Self {
        Self::new()
    }
}

unsafe impl Send for MIKEYMessage {}