gio/
tls_connection.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#[cfg(feature = "v2_66")]
4use std::ptr;
5
6use glib::prelude::*;
7#[cfg(feature = "v2_60")]
8use glib::translate::*;
9
10#[cfg(feature = "v2_66")]
11use crate::TlsChannelBindingType;
12use crate::TlsConnection;
13
14pub trait TlsConnectionExtManual: IsA<TlsConnection> {
15    /// Query the TLS backend for TLS channel binding data of @type_ for @self.
16    ///
17    /// This call retrieves TLS channel binding data as specified in RFC
18    /// [5056](https://tools.ietf.org/html/rfc5056), RFC
19    /// [5929](https://tools.ietf.org/html/rfc5929), and related RFCs.  The
20    /// binding data is returned in @data.  The @data is resized by the callee
21    /// using #GByteArray buffer management and will be freed when the @data
22    /// is destroyed by g_byte_array_unref(). If @data is [`None`], it will only
23    /// check whether TLS backend is able to fetch the data (e.g. whether @type_
24    /// is supported by the TLS backend). It does not guarantee that the data
25    /// will be available though.  That could happen if TLS connection does not
26    /// support @type_ or the binding data is not available yet due to additional
27    /// negotiation or input required.
28    /// ## `type_`
29    /// #GTlsChannelBindingType type of data to fetch
30    ///
31    /// # Returns
32    ///
33    /// [`true`] on success, [`false`] otherwise
34    ///
35    /// ## `data`
36    /// #GByteArray is
37    ///        filled with the binding data, or [`None`]
38    #[cfg(feature = "v2_66")]
39    #[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
40    #[doc(alias = "g_tls_connection_get_channel_binding_data")]
41    #[doc(alias = "get_channel_binding_data")]
42    fn channel_binding_data(
43        &self,
44        type_: TlsChannelBindingType,
45    ) -> Result<glib::ByteArray, glib::Error> {
46        unsafe {
47            let data = ptr::null_mut();
48            let mut error = ptr::null_mut();
49            let _ = crate::ffi::g_tls_connection_get_channel_binding_data(
50                self.as_ptr() as *mut _,
51                type_.into_glib(),
52                data,
53                &mut error,
54            );
55            if error.is_null() {
56                Ok(from_glib_none(data))
57            } else {
58                Err(from_glib_full(error))
59            }
60        }
61    }
62
63    /// Sets the list of application-layer protocols to advertise that the
64    /// caller is willing to speak on this connection. The
65    /// Application-Layer Protocol Negotiation (ALPN) extension will be
66    /// used to negotiate a compatible protocol with the peer; use
67    /// g_tls_connection_get_negotiated_protocol() to find the negotiated
68    /// protocol after the handshake.  Specifying [`None`] for the the value
69    /// of @protocols will disable ALPN negotiation.
70    ///
71    /// See [IANA TLS ALPN Protocol IDs](https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)
72    /// for a list of registered protocol IDs.
73    /// ## `protocols`
74    /// a [`None`]-terminated
75    ///   array of ALPN protocol names (eg, "http/1.1", "h2"), or [`None`]
76    #[cfg(feature = "v2_60")]
77    #[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
78    #[doc(alias = "g_tls_connection_set_advertised_protocols")]
79    fn set_advertised_protocols(&self, protocols: impl IntoStrV) {
80        unsafe {
81            protocols.run_with_strv(|protocols| {
82                crate::ffi::g_tls_connection_set_advertised_protocols(
83                    self.as_ref().to_glib_none().0,
84                    protocols.as_ptr() as *mut _,
85                );
86            })
87        }
88    }
89}
90
91impl<O: IsA<TlsConnection>> TlsConnectionExtManual for O {}