gio/auto/
tls_server_connection.rs

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
// 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 crate::{ffi, IOStream, TlsAuthenticationMode, TlsCertificate, TlsConnection};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// `GTlsServerConnection` is the server-side subclass of
    /// [`TlsConnection`][crate::TlsConnection], representing a server-side TLS connection.
    ///
    /// ## Properties
    ///
    ///
    /// #### `authentication-mode`
    ///  The #GTlsAuthenticationMode for the server. This can be changed
    /// before calling g_tls_connection_handshake() if you want to
    /// rehandshake with a different mode from the initial handshake.
    ///
    /// Readable | Writeable
    /// <details><summary><h4>TlsConnection</h4></summary>
    ///
    ///
    /// #### `advertised-protocols`
    ///  The list of application-layer protocols that the connection
    /// advertises that it is willing to speak. See
    /// g_tls_connection_set_advertised_protocols().
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `base-io-stream`
    ///  The #GIOStream that the connection wraps. The connection holds a reference
    /// to this stream, and may run operations on the stream from other threads
    /// throughout its lifetime. Consequently, after the #GIOStream has been
    /// constructed, application code may only run its own operations on this
    /// stream when no #GIOStream operations are running.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `certificate`
    ///  The connection's certificate; see
    /// g_tls_connection_set_certificate().
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `ciphersuite-name`
    ///  The name of the TLS ciphersuite in use. See g_tls_connection_get_ciphersuite_name().
    ///
    /// Readable
    ///
    ///
    /// #### `database`
    ///  The certificate database to use when verifying this TLS connection.
    /// If no certificate database is set, then the default database will be
    /// used. See g_tls_backend_get_default_database().
    ///
    /// When using a non-default database, #GTlsConnection must fall back to using
    /// the #GTlsDatabase to perform certificate verification using
    /// g_tls_database_verify_chain(), which means certificate verification will
    /// not be able to make use of TLS session context. This may be less secure.
    /// For example, if you create your own #GTlsDatabase that just wraps the
    /// default #GTlsDatabase, you might expect that you have not changed anything,
    /// but this is not true because you may have altered the behavior of
    /// #GTlsConnection by causing it to use g_tls_database_verify_chain(). See the
    /// documentation of g_tls_database_verify_chain() for more details on specific
    /// security checks that may not be performed. Accordingly, setting a
    /// non-default database is discouraged except for specialty applications with
    /// unusual security requirements.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `interaction`
    ///  A #GTlsInteraction object to be used when the connection or certificate
    /// database need to interact with the user. This will be used to prompt the
    /// user for passwords where necessary.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `negotiated-protocol`
    ///  The application-layer protocol negotiated during the TLS
    /// handshake. See g_tls_connection_get_negotiated_protocol().
    ///
    /// Readable
    ///
    ///
    /// #### `peer-certificate`
    ///  The connection's peer's certificate, after the TLS handshake has
    /// completed or failed. Note in particular that this is not yet set
    /// during the emission of #GTlsConnection::accept-certificate.
    ///
    /// (You can watch for a #GObject::notify signal on this property to
    /// detect when a handshake has occurred.)
    ///
    /// Readable
    ///
    ///
    /// #### `peer-certificate-errors`
    ///  The errors noticed while verifying
    /// #GTlsConnection:peer-certificate. Normally this should be 0, but
    /// it may not be if #GTlsClientConnection:validation-flags is not
    /// [`TlsCertificateFlags::VALIDATE_ALL`][crate::TlsCertificateFlags::VALIDATE_ALL], or if
    /// #GTlsConnection::accept-certificate overrode the default
    /// behavior.
    ///
    /// GLib guarantees that if certificate verification fails, at least
    /// one error will be set, but it does not guarantee that all possible
    /// errors will be set. Accordingly, you may not safely decide to
    /// ignore any particular type of error. For example, it would be
    /// incorrect to mask [`TlsCertificateFlags::EXPIRED`][crate::TlsCertificateFlags::EXPIRED] if you want to allow
    /// expired certificates, because this could potentially be the only
    /// error flag set even if other problems exist with the certificate.
    ///
    /// Readable
    ///
    ///
    /// #### `protocol-version`
    ///  The TLS protocol version in use. See g_tls_connection_get_protocol_version().
    ///
    /// Readable
    ///
    ///
    /// #### `rehandshake-mode`
    ///  The rehandshaking mode. See
    /// g_tls_connection_set_rehandshake_mode().
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `require-close-notify`
    ///  Whether or not proper TLS close notification is required.
    /// See g_tls_connection_set_require_close_notify().
    ///
    /// Readable | Writeable | Construct
    ///
    ///
    /// #### `use-system-certdb`
    ///  Whether or not the system certificate database will be used to
    /// verify peer certificates. See
    /// g_tls_connection_set_use_system_certdb().
    ///
    /// Readable | Writeable | Construct
    /// </details>
    /// <details><summary><h4>IOStream</h4></summary>
    ///
    ///
    /// #### `closed`
    ///  Whether the stream is closed.
    ///
    /// Readable
    ///
    ///
    /// #### `input-stream`
    ///  The [`InputStream`][crate::InputStream] to read from.
    ///
    /// Readable
    ///
    ///
    /// #### `output-stream`
    ///  The [`OutputStream`][crate::OutputStream] to write to.
    ///
    /// Readable
    /// </details>
    ///
    /// # Implements
    ///
    /// [`TlsServerConnectionExt`][trait@crate::prelude::TlsServerConnectionExt], [`TlsConnectionExt`][trait@crate::prelude::TlsConnectionExt], [`IOStreamExt`][trait@crate::prelude::IOStreamExt], [`trait@glib::ObjectExt`], [`TlsConnectionExtManual`][trait@crate::prelude::TlsConnectionExtManual], [`IOStreamExtManual`][trait@crate::prelude::IOStreamExtManual]
    #[doc(alias = "GTlsServerConnection")]
    pub struct TlsServerConnection(Interface<ffi::GTlsServerConnection, ffi::GTlsServerConnectionInterface>) @requires TlsConnection, IOStream;

    match fn {
        type_ => || ffi::g_tls_server_connection_get_type(),
    }
}

impl TlsServerConnection {
    pub const NONE: Option<&'static TlsServerConnection> = None;

    /// Creates a new #GTlsServerConnection wrapping @base_io_stream (which
    /// must have pollable input and output streams).
    ///
    /// See the documentation for #GTlsConnection:base-io-stream for restrictions
    /// on when application code can run operations on the @base_io_stream after
    /// this function has returned.
    /// ## `base_io_stream`
    /// the #GIOStream to wrap
    /// ## `certificate`
    /// the default server certificate, or [`None`]
    ///
    /// # Returns
    ///
    /// the new
    /// #GTlsServerConnection, or [`None`] on error
    #[doc(alias = "g_tls_server_connection_new")]
    pub fn new(
        base_io_stream: &impl IsA<IOStream>,
        certificate: Option<&impl IsA<TlsCertificate>>,
    ) -> Result<TlsServerConnection, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::g_tls_server_connection_new(
                base_io_stream.as_ref().to_glib_none().0,
                certificate.map(|p| p.as_ref()).to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

/// Trait containing all [`struct@TlsServerConnection`] methods.
///
/// # Implementors
///
/// [`TlsServerConnection`][struct@crate::TlsServerConnection]
pub trait TlsServerConnectionExt: IsA<TlsServerConnection> + 'static {
    /// The #GTlsAuthenticationMode for the server. This can be changed
    /// before calling g_tls_connection_handshake() if you want to
    /// rehandshake with a different mode from the initial handshake.
    #[doc(alias = "authentication-mode")]
    fn authentication_mode(&self) -> TlsAuthenticationMode {
        ObjectExt::property(self.as_ref(), "authentication-mode")
    }

    /// The #GTlsAuthenticationMode for the server. This can be changed
    /// before calling g_tls_connection_handshake() if you want to
    /// rehandshake with a different mode from the initial handshake.
    #[doc(alias = "authentication-mode")]
    fn set_authentication_mode(&self, authentication_mode: TlsAuthenticationMode) {
        ObjectExt::set_property(self.as_ref(), "authentication-mode", authentication_mode)
    }

    #[doc(alias = "authentication-mode")]
    fn connect_authentication_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_authentication_mode_trampoline<
            P: IsA<TlsServerConnection>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GTlsServerConnection,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(TlsServerConnection::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::authentication-mode\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_authentication_mode_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<TlsServerConnection>> TlsServerConnectionExt for O {}