gio/auto/
dtls_server_connection.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, DatagramBased, DtlsConnection, TlsAuthenticationMode, TlsCertificate};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// `GDtlsServerConnection` is the server-side subclass of
15    /// [`DtlsConnection`][crate::DtlsConnection], representing a server-side DTLS connection.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `authentication-mode`
21    ///  The #GTlsAuthenticationMode for the server. This can be changed
22    /// before calling g_dtls_connection_handshake() if you want to
23    /// rehandshake with a different mode from the initial handshake.
24    ///
25    /// Readable | Writeable
26    /// <details><summary><h4>DtlsConnection</h4></summary>
27    ///
28    ///
29    /// #### `advertised-protocols`
30    ///  The list of application-layer protocols that the connection
31    /// advertises that it is willing to speak. See
32    /// g_dtls_connection_set_advertised_protocols().
33    ///
34    /// Readable | Writeable
35    ///
36    ///
37    /// #### `base-socket`
38    ///  The #GDatagramBased that the connection wraps. Note that this may be any
39    /// implementation of #GDatagramBased, not just a #GSocket.
40    ///
41    /// Readable | Writeable | Construct Only
42    ///
43    ///
44    /// #### `certificate`
45    ///  The connection's certificate; see
46    /// g_dtls_connection_set_certificate().
47    ///
48    /// Readable | Writeable
49    ///
50    ///
51    /// #### `ciphersuite-name`
52    ///  The name of the DTLS ciphersuite in use. See g_dtls_connection_get_ciphersuite_name().
53    ///
54    /// Readable
55    ///
56    ///
57    /// #### `database`
58    ///  The certificate database to use when verifying this TLS connection.
59    /// If no certificate database is set, then the default database will be
60    /// used. See g_tls_backend_get_default_database().
61    ///
62    /// When using a non-default database, #GDtlsConnection must fall back to using
63    /// the #GTlsDatabase to perform certificate verification using
64    /// g_tls_database_verify_chain(), which means certificate verification will
65    /// not be able to make use of TLS session context. This may be less secure.
66    /// For example, if you create your own #GTlsDatabase that just wraps the
67    /// default #GTlsDatabase, you might expect that you have not changed anything,
68    /// but this is not true because you may have altered the behavior of
69    /// #GDtlsConnection by causing it to use g_tls_database_verify_chain(). See the
70    /// documentation of g_tls_database_verify_chain() for more details on specific
71    /// security checks that may not be performed. Accordingly, setting a
72    /// non-default database is discouraged except for specialty applications with
73    /// unusual security requirements.
74    ///
75    /// Readable | Writeable
76    ///
77    ///
78    /// #### `interaction`
79    ///  A #GTlsInteraction object to be used when the connection or certificate
80    /// database need to interact with the user. This will be used to prompt the
81    /// user for passwords where necessary.
82    ///
83    /// Readable | Writeable
84    ///
85    ///
86    /// #### `negotiated-protocol`
87    ///  The application-layer protocol negotiated during the TLS
88    /// handshake. See g_dtls_connection_get_negotiated_protocol().
89    ///
90    /// Readable
91    ///
92    ///
93    /// #### `peer-certificate`
94    ///  The connection's peer's certificate, after the TLS handshake has
95    /// completed or failed. Note in particular that this is not yet set
96    /// during the emission of #GDtlsConnection::accept-certificate.
97    ///
98    /// (You can watch for a #GObject::notify signal on this property to
99    /// detect when a handshake has occurred.)
100    ///
101    /// Readable
102    ///
103    ///
104    /// #### `peer-certificate-errors`
105    ///  The errors noticed while verifying
106    /// #GDtlsConnection:peer-certificate. Normally this should be 0, but
107    /// it may not be if #GDtlsClientConnection:validation-flags is not
108    /// [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL], or if
109    /// #GDtlsConnection::accept-certificate overrode the default
110    /// behavior.
111    ///
112    /// GLib guarantees that if certificate verification fails, at least
113    /// one error will be set, but it does not guarantee that all possible
114    /// errors will be set. Accordingly, you may not safely decide to
115    /// ignore any particular type of error. For example, it would be
116    /// incorrect to mask [`TlsCertificateFlags::EXPIRED`][crate::TlsCertificateFlags::EXPIRED] if you want to allow
117    /// expired certificates, because this could potentially be the only
118    /// error flag set even if other problems exist with the certificate.
119    ///
120    /// Readable
121    ///
122    ///
123    /// #### `protocol-version`
124    ///  The DTLS protocol version in use. See g_dtls_connection_get_protocol_version().
125    ///
126    /// Readable
127    ///
128    ///
129    /// #### `rehandshake-mode`
130    ///  The rehandshaking mode. See
131    /// g_dtls_connection_set_rehandshake_mode().
132    ///
133    /// Readable | Writeable | Construct
134    ///
135    ///
136    /// #### `require-close-notify`
137    ///  Whether or not proper TLS close notification is required.
138    /// See g_dtls_connection_set_require_close_notify().
139    ///
140    /// Readable | Writeable | Construct
141    /// </details>
142    ///
143    /// # Implements
144    ///
145    /// [`DtlsServerConnectionExt`][trait@crate::prelude::DtlsServerConnectionExt], [`DatagramBasedExt`][trait@crate::prelude::DatagramBasedExt], [`DtlsConnectionExt`][trait@crate::prelude::DtlsConnectionExt], [`DatagramBasedExtManual`][trait@crate::prelude::DatagramBasedExtManual]
146    #[doc(alias = "GDtlsServerConnection")]
147    pub struct DtlsServerConnection(Interface<ffi::GDtlsServerConnection, ffi::GDtlsServerConnectionInterface>) @requires DatagramBased, DtlsConnection;
148
149    match fn {
150        type_ => || ffi::g_dtls_server_connection_get_type(),
151    }
152}
153
154impl DtlsServerConnection {
155    pub const NONE: Option<&'static DtlsServerConnection> = None;
156
157    /// Creates a new #GDtlsServerConnection wrapping @base_socket.
158    /// ## `base_socket`
159    /// the #GDatagramBased to wrap
160    /// ## `certificate`
161    /// the default server certificate, or [`None`]
162    ///
163    /// # Returns
164    ///
165    /// the new
166    ///   #GDtlsServerConnection, or [`None`] on error
167    #[doc(alias = "g_dtls_server_connection_new")]
168    pub fn new(
169        base_socket: &impl IsA<DatagramBased>,
170        certificate: Option<&impl IsA<TlsCertificate>>,
171    ) -> Result<DtlsServerConnection, glib::Error> {
172        unsafe {
173            let mut error = std::ptr::null_mut();
174            let ret = ffi::g_dtls_server_connection_new(
175                base_socket.as_ref().to_glib_none().0,
176                certificate.map(|p| p.as_ref()).to_glib_none().0,
177                &mut error,
178            );
179            if error.is_null() {
180                Ok(from_glib_full(ret))
181            } else {
182                Err(from_glib_full(error))
183            }
184        }
185    }
186}
187
188mod sealed {
189    pub trait Sealed {}
190    impl<T: super::IsA<super::DtlsServerConnection>> Sealed for T {}
191}
192
193/// Trait containing all [`struct@DtlsServerConnection`] methods.
194///
195/// # Implementors
196///
197/// [`DtlsServerConnection`][struct@crate::DtlsServerConnection]
198pub trait DtlsServerConnectionExt: IsA<DtlsServerConnection> + sealed::Sealed + 'static {
199    /// The #GTlsAuthenticationMode for the server. This can be changed
200    /// before calling g_dtls_connection_handshake() if you want to
201    /// rehandshake with a different mode from the initial handshake.
202    #[doc(alias = "authentication-mode")]
203    fn authentication_mode(&self) -> TlsAuthenticationMode {
204        ObjectExt::property(self.as_ref(), "authentication-mode")
205    }
206
207    /// The #GTlsAuthenticationMode for the server. This can be changed
208    /// before calling g_dtls_connection_handshake() if you want to
209    /// rehandshake with a different mode from the initial handshake.
210    #[doc(alias = "authentication-mode")]
211    fn set_authentication_mode(&self, authentication_mode: TlsAuthenticationMode) {
212        ObjectExt::set_property(self.as_ref(), "authentication-mode", authentication_mode)
213    }
214
215    #[doc(alias = "authentication-mode")]
216    fn connect_authentication_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217        unsafe extern "C" fn notify_authentication_mode_trampoline<
218            P: IsA<DtlsServerConnection>,
219            F: Fn(&P) + 'static,
220        >(
221            this: *mut ffi::GDtlsServerConnection,
222            _param_spec: glib::ffi::gpointer,
223            f: glib::ffi::gpointer,
224        ) {
225            let f: &F = &*(f as *const F);
226            f(DtlsServerConnection::from_glib_borrow(this).unsafe_cast_ref())
227        }
228        unsafe {
229            let f: Box_<F> = Box_::new(f);
230            connect_raw(
231                self.as_ptr() as *mut _,
232                b"notify::authentication-mode\0".as_ptr() as *const _,
233                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234                    notify_authentication_mode_trampoline::<Self, F> as *const (),
235                )),
236                Box_::into_raw(f),
237            )
238        }
239    }
240}
241
242impl<O: IsA<DtlsServerConnection>> DtlsServerConnectionExt for O {}