nm_rs/auto/
wire_guard_peer.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{SettingCompareFlags, SettingSecretFlags, ffi};
7use glib::translate::*;
8
9glib::wrapper! {
10    /// The settings of one WireGuard peer.
11    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12    pub struct WireGuardPeer(Shared<ffi::NMWireGuardPeer>);
13
14    match fn {
15        ref => |ptr| ffi::nm_wireguard_peer_ref(ptr),
16        unref => |ptr| ffi::nm_wireguard_peer_unref(ptr),
17        type_ => || ffi::nm_wireguard_peer_get_type(),
18    }
19}
20
21impl WireGuardPeer {
22    ///
23    /// # Returns
24    ///
25    /// a new, default, unsealed #NMWireGuardPeer instance.
26    #[doc(alias = "nm_wireguard_peer_new")]
27    pub fn new() -> WireGuardPeer {
28        assert_initialized_main_thread!();
29        unsafe { from_glib_full(ffi::nm_wireguard_peer_new()) }
30    }
31
32    /// Appends @allowed_ip setting to the list. This does not check
33    /// for duplicates and always appends @allowed_ip to the end of the
34    /// list. If @allowed_ip is valid, it will be normalized and a modified
35    /// for might be appended. If @allowed_ip is invalid, it will still be
36    /// appended, but later verification will fail.
37    ///
38    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
39    /// ## `allowed_ip`
40    /// the allowed-ip entry to set.
41    /// ## `accept_invalid`
42    /// if [`true`], also invalid @allowed_ip value
43    ///   will be appended. Otherwise, the function does nothing
44    ///   in face of invalid values and returns [`false`].
45    ///
46    /// # Returns
47    ///
48    /// [`true`] if the value is a valid allowed-ips value, [`false`] otherwise.
49    ///   Depending on @accept_invalid, also invalid values are added.
50    #[doc(alias = "nm_wireguard_peer_append_allowed_ip")]
51    pub fn append_allowed_ip(&self, allowed_ip: &str, accept_invalid: bool) -> bool {
52        unsafe {
53            from_glib(ffi::nm_wireguard_peer_append_allowed_ip(
54                self.to_glib_none().0,
55                allowed_ip.to_glib_none().0,
56                accept_invalid.into_glib(),
57            ))
58        }
59    }
60
61    /// Removes all allowed-ip entries.
62    ///
63    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
64    #[doc(alias = "nm_wireguard_peer_clear_allowed_ips")]
65    pub fn clear_allowed_ips(&self) {
66        unsafe {
67            ffi::nm_wireguard_peer_clear_allowed_ips(self.to_glib_none().0);
68        }
69    }
70
71    /// ## `b`
72    /// the other #NMWireGuardPeer to compare.
73    /// ## `compare_flags`
74    /// #NMSettingCompareFlags to affect the comparison.
75    ///
76    /// # Returns
77    ///
78    /// zero of the two instances are equivalent or
79    ///   a non-zero integer otherwise. This defines a total ordering
80    ///   over the peers. Whether a peer is sealed or not, does not
81    ///   affect the comparison.
82    #[doc(alias = "nm_wireguard_peer_cmp")]
83    pub fn cmp(&self, b: Option<&WireGuardPeer>, compare_flags: SettingCompareFlags) -> i32 {
84        unsafe {
85            ffi::nm_wireguard_peer_cmp(
86                self.to_glib_none().0,
87                b.to_glib_none().0,
88                compare_flags.into_glib(),
89            )
90        }
91    }
92
93    /// ## `idx`
94    /// the index from zero to (allowed-ips-len - 1) to
95    ///   retrieve.
96    /// ## `out_is_valid`
97    /// [`true`] if the returned value is a valid allowed-ip
98    ///   setting.
99    ///   This parameter is wrongly not marked as (out) argument, it is
100    ///   thus not accessible via introspection. This cannot be fixed without
101    ///   breaking API for introspection users.
102    ///
103    /// # Returns
104    ///
105    /// the allowed-ip setting at index @idx.
106    ///   If @idx is out of range, [`None`] will be returned.
107    #[doc(alias = "nm_wireguard_peer_get_allowed_ip")]
108    #[doc(alias = "get_allowed_ip")]
109    pub fn allowed_ip(&self, idx: u32, out_is_valid: bool) -> Option<glib::GString> {
110        unsafe {
111            from_glib_none(ffi::nm_wireguard_peer_get_allowed_ip(
112                self.to_glib_none().0,
113                idx,
114                &mut out_is_valid.into_glib(),
115            ))
116        }
117    }
118
119    ///
120    /// # Returns
121    ///
122    /// the number of allowed-ips entries.
123    #[doc(alias = "nm_wireguard_peer_get_allowed_ips_len")]
124    #[doc(alias = "get_allowed_ips_len")]
125    pub fn allowed_ips_len(&self) -> u32 {
126        unsafe { ffi::nm_wireguard_peer_get_allowed_ips_len(self.to_glib_none().0) }
127    }
128
129    ///
130    /// # Returns
131    ///
132    /// the endpoint or [`None`] if none was set.
133    #[doc(alias = "nm_wireguard_peer_get_endpoint")]
134    #[doc(alias = "get_endpoint")]
135    pub fn endpoint(&self) -> glib::GString {
136        unsafe { from_glib_none(ffi::nm_wireguard_peer_get_endpoint(self.to_glib_none().0)) }
137    }
138
139    ///
140    /// # Returns
141    ///
142    /// get the persistent-keepalive setting in seconds. Set to zero to disable
143    ///   keep-alive.
144    #[doc(alias = "nm_wireguard_peer_get_persistent_keepalive")]
145    #[doc(alias = "get_persistent_keepalive")]
146    pub fn persistent_keepalive(&self) -> u16 {
147        unsafe { ffi::nm_wireguard_peer_get_persistent_keepalive(self.to_glib_none().0) }
148    }
149
150    ///
151    /// # Returns
152    ///
153    /// the preshared key or [`None`] if unset.
154    #[doc(alias = "nm_wireguard_peer_get_preshared_key")]
155    #[doc(alias = "get_preshared_key")]
156    pub fn preshared_key(&self) -> glib::GString {
157        unsafe {
158            from_glib_none(ffi::nm_wireguard_peer_get_preshared_key(
159                self.to_glib_none().0,
160            ))
161        }
162    }
163
164    ///
165    /// # Returns
166    ///
167    /// get the secret flags for the preshared-key.
168    #[doc(alias = "nm_wireguard_peer_get_preshared_key_flags")]
169    #[doc(alias = "get_preshared_key_flags")]
170    pub fn preshared_key_flags(&self) -> SettingSecretFlags {
171        unsafe {
172            from_glib(ffi::nm_wireguard_peer_get_preshared_key_flags(
173                self.to_glib_none().0,
174            ))
175        }
176    }
177
178    ///
179    /// # Returns
180    ///
181    /// the public key or [`None`] if unset.
182    #[doc(alias = "nm_wireguard_peer_get_public_key")]
183    #[doc(alias = "get_public_key")]
184    pub fn public_key(&self) -> glib::GString {
185        unsafe { from_glib_none(ffi::nm_wireguard_peer_get_public_key(self.to_glib_none().0)) }
186    }
187
188    ///
189    /// # Returns
190    ///
191    /// whether @self is sealed or not.
192    #[doc(alias = "nm_wireguard_peer_is_sealed")]
193    pub fn is_sealed(&self) -> bool {
194        unsafe { from_glib(ffi::nm_wireguard_peer_is_sealed(self.to_glib_none().0)) }
195    }
196
197    /// ## `check_non_secrets`
198    /// if [`true`], secret properties are validated.
199    ///   Otherwise, they are ignored for this purpose.
200    /// ## `check_secrets`
201    /// if [`true`], non-secret properties are validated.
202    ///   Otherwise, they are ignored for this purpose.
203    ///
204    /// # Returns
205    ///
206    /// [`true`] if the peer is valid or fails with an error
207    ///   reason.
208    #[doc(alias = "nm_wireguard_peer_is_valid")]
209    pub fn is_valid(
210        &self,
211        check_non_secrets: bool,
212        check_secrets: bool,
213    ) -> Result<(), glib::Error> {
214        unsafe {
215            let mut error = std::ptr::null_mut();
216            let is_ok = ffi::nm_wireguard_peer_is_valid(
217                self.to_glib_none().0,
218                check_non_secrets.into_glib(),
219                check_secrets.into_glib(),
220                &mut error,
221            );
222            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
223            if error.is_null() {
224                Ok(())
225            } else {
226                Err(from_glib_full(error))
227            }
228        }
229    }
230
231    /// ## `with_secrets`
232    /// if [`true`], the preshared-key secrets are copied
233    ///  as well. Otherwise, they will be removed.
234    ///
235    /// # Returns
236    ///
237    /// a clone of @self. This instance
238    ///   is always unsealed.
239    #[doc(alias = "nm_wireguard_peer_new_clone")]
240    #[must_use]
241    pub fn new_clone(&self, with_secrets: bool) -> WireGuardPeer {
242        unsafe {
243            from_glib_full(ffi::nm_wireguard_peer_new_clone(
244                self.to_glib_none().0,
245                with_secrets.into_glib(),
246            ))
247        }
248    }
249
250    /// Removes the allowed-ip at the given @idx. This shifts all
251    /// following entries one index down.
252    ///
253    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
254    /// ## `idx`
255    /// the index from zero to (allowed-ips-len - 1) to
256    ///   retrieve. If the index is out of range, [`false`] is returned
257    ///   and nothing is done.
258    ///
259    /// # Returns
260    ///
261    /// [`true`] if @idx was valid and the allowed-ip was removed.
262    ///   [`false`] otherwise, and the peer will not be changed.
263    #[doc(alias = "nm_wireguard_peer_remove_allowed_ip")]
264    pub fn remove_allowed_ip(&self, idx: u32) -> bool {
265        unsafe {
266            from_glib(ffi::nm_wireguard_peer_remove_allowed_ip(
267                self.to_glib_none().0,
268                idx,
269            ))
270        }
271    }
272
273    /// Seal the #NMWireGuardPeer instance. Afterwards, it is a bug
274    /// to call all functions that modify the instance (except ref/unref).
275    /// A sealed instance cannot be unsealed again, but you can create
276    /// an unsealed copy with nm_wireguard_peer_new_clone().
277    #[doc(alias = "nm_wireguard_peer_seal")]
278    pub fn seal(&self) {
279        unsafe {
280            ffi::nm_wireguard_peer_seal(self.to_glib_none().0);
281        }
282    }
283
284    /// Sets or clears the endpoint of @self.
285    ///
286    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
287    /// ## `endpoint`
288    /// the socket address endpoint to set or [`None`].
289    /// ## `allow_invalid`
290    /// if [`true`], also invalid values are set.
291    ///   If [`false`], the function does nothing for invalid @endpoint
292    ///   arguments.
293    ///
294    /// # Returns
295    ///
296    /// [`true`] if the endpoint is [`None`] or valid. For an
297    ///   invalid @endpoint argument, [`false`] is returned. Depending
298    ///   on @allow_invalid, the instance will be modified.
299    #[doc(alias = "nm_wireguard_peer_set_endpoint")]
300    pub fn set_endpoint(&self, endpoint: &str, allow_invalid: bool) -> bool {
301        unsafe {
302            from_glib(ffi::nm_wireguard_peer_set_endpoint(
303                self.to_glib_none().0,
304                endpoint.to_glib_none().0,
305                allow_invalid.into_glib(),
306            ))
307        }
308    }
309
310    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
311    /// ## `persistent_keepalive`
312    /// the keep-alive value to set.
313    #[doc(alias = "nm_wireguard_peer_set_persistent_keepalive")]
314    pub fn set_persistent_keepalive(&self, persistent_keepalive: u16) {
315        unsafe {
316            ffi::nm_wireguard_peer_set_persistent_keepalive(
317                self.to_glib_none().0,
318                persistent_keepalive,
319            );
320        }
321    }
322
323    /// Reset the preshared key. Note that if the preshared key is valid, it
324    /// will be normalized (which may or may not modify the set value).
325    ///
326    /// Note that the preshared-key is a secret and consequently has corresponding
327    /// preshared-key-flags property. This is so that secrets can be optional
328    /// and requested on demand from a secret-agent. Also, an invalid  preshared-key
329    /// may optionally cause nm_wireguard_peer_is_valid() to fail or it may
330    /// be accepted.
331    ///
332    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
333    /// ## `preshared_key`
334    /// the new preshared
335    ///   key or [`None`] to clear the preshared key.
336    /// ## `accept_invalid`
337    /// whether to allow setting the key to an invalid
338    ///   value. If [`false`], @self is unchanged if the key is invalid
339    ///   and if [`false`] is returned.
340    ///
341    /// # Returns
342    ///
343    /// [`true`] if the preshared-key is valid, otherwise [`false`].
344    ///   [`None`] is considered a valid value.
345    ///   If the key is invalid, it depends on @accept_invalid whether the
346    ///   previous value was reset.
347    #[doc(alias = "nm_wireguard_peer_set_preshared_key")]
348    pub fn set_preshared_key(&self, preshared_key: Option<&str>, accept_invalid: bool) -> bool {
349        unsafe {
350            from_glib(ffi::nm_wireguard_peer_set_preshared_key(
351                self.to_glib_none().0,
352                preshared_key.to_glib_none().0,
353                accept_invalid.into_glib(),
354            ))
355        }
356    }
357
358    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
359    /// ## `preshared_key_flags`
360    /// the secret flags to set.
361    #[doc(alias = "nm_wireguard_peer_set_preshared_key_flags")]
362    pub fn set_preshared_key_flags(&self, preshared_key_flags: SettingSecretFlags) {
363        unsafe {
364            ffi::nm_wireguard_peer_set_preshared_key_flags(
365                self.to_glib_none().0,
366                preshared_key_flags.into_glib(),
367            );
368        }
369    }
370
371    /// Reset the public key. Note that if the public key is valid, it
372    /// will be normalized (which may or may not modify the set value).
373    ///
374    /// It is a bug trying to modify a sealed #NMWireGuardPeer instance.
375    /// ## `public_key`
376    /// the new public
377    ///   key or [`None`] to clear the public key.
378    /// ## `accept_invalid`
379    /// if [`true`] and @public_key is not [`None`] and
380    ///   invalid, then do not modify the instance.
381    ///
382    /// # Returns
383    ///
384    /// [`true`] if the key was valid or [`None`]. Returns
385    ///   [`false`] for invalid keys. Depending on @accept_invalid
386    ///   will an invalid key be set or not.
387    #[doc(alias = "nm_wireguard_peer_set_public_key")]
388    pub fn set_public_key(&self, public_key: Option<&str>, accept_invalid: bool) -> bool {
389        unsafe {
390            from_glib(ffi::nm_wireguard_peer_set_public_key(
391                self.to_glib_none().0,
392                public_key.to_glib_none().0,
393                accept_invalid.into_glib(),
394            ))
395        }
396    }
397}
398
399#[cfg(feature = "v1_16")]
400#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
401impl Default for WireGuardPeer {
402    fn default() -> Self {
403        Self::new()
404    }
405}