gio/auto/tls_file_database.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, TlsDatabase};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// `GTlsFileDatabase` is implemented by [`TlsDatabase`][crate::TlsDatabase] objects which
15 /// load their certificate information from a file. It is an interface which
16 /// TLS library specific subtypes implement.
17 ///
18 /// ## Properties
19 ///
20 ///
21 /// #### `anchors`
22 /// The path to a file containing PEM encoded certificate authority
23 /// root anchors. The certificates in this file will be treated as
24 /// root authorities for the purpose of verifying other certificates
25 /// via the g_tls_database_verify_chain() operation.
26 ///
27 /// Readable | Writeable | Construct
28 ///
29 /// # Implements
30 ///
31 /// [`TlsFileDatabaseExt`][trait@crate::prelude::TlsFileDatabaseExt], [`TlsDatabaseExt`][trait@crate::prelude::TlsDatabaseExt], [`trait@glib::ObjectExt`]
32 #[doc(alias = "GTlsFileDatabase")]
33 pub struct TlsFileDatabase(Interface<ffi::GTlsFileDatabase, ffi::GTlsFileDatabaseInterface>) @requires TlsDatabase;
34
35 match fn {
36 type_ => || ffi::g_tls_file_database_get_type(),
37 }
38}
39
40impl TlsFileDatabase {
41 pub const NONE: Option<&'static TlsFileDatabase> = None;
42
43 /// Creates a new #GTlsFileDatabase which uses anchor certificate authorities
44 /// in @anchors to verify certificate chains.
45 ///
46 /// The certificates in @anchors must be PEM encoded.
47 /// ## `anchors`
48 /// filename of anchor certificate authorities.
49 ///
50 /// # Returns
51 ///
52 /// the new
53 /// #GTlsFileDatabase, or [`None`] on error
54 #[doc(alias = "g_tls_file_database_new")]
55 pub fn new(anchors: impl AsRef<std::path::Path>) -> Result<TlsFileDatabase, glib::Error> {
56 unsafe {
57 let mut error = std::ptr::null_mut();
58 let ret = ffi::g_tls_file_database_new(anchors.as_ref().to_glib_none().0, &mut error);
59 if error.is_null() {
60 Ok(from_glib_full(ret))
61 } else {
62 Err(from_glib_full(error))
63 }
64 }
65 }
66}
67
68mod sealed {
69 pub trait Sealed {}
70 impl<T: super::IsA<super::TlsFileDatabase>> Sealed for T {}
71}
72
73/// Trait containing all [`struct@TlsFileDatabase`] methods.
74///
75/// # Implementors
76///
77/// [`TlsFileDatabase`][struct@crate::TlsFileDatabase]
78pub trait TlsFileDatabaseExt: IsA<TlsFileDatabase> + sealed::Sealed + 'static {
79 /// The path to a file containing PEM encoded certificate authority
80 /// root anchors. The certificates in this file will be treated as
81 /// root authorities for the purpose of verifying other certificates
82 /// via the g_tls_database_verify_chain() operation.
83 fn anchors(&self) -> Option<glib::GString> {
84 ObjectExt::property(self.as_ref(), "anchors")
85 }
86
87 /// The path to a file containing PEM encoded certificate authority
88 /// root anchors. The certificates in this file will be treated as
89 /// root authorities for the purpose of verifying other certificates
90 /// via the g_tls_database_verify_chain() operation.
91 fn set_anchors(&self, anchors: Option<&str>) {
92 ObjectExt::set_property(self.as_ref(), "anchors", anchors)
93 }
94
95 #[doc(alias = "anchors")]
96 fn connect_anchors_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
97 unsafe extern "C" fn notify_anchors_trampoline<
98 P: IsA<TlsFileDatabase>,
99 F: Fn(&P) + 'static,
100 >(
101 this: *mut ffi::GTlsFileDatabase,
102 _param_spec: glib::ffi::gpointer,
103 f: glib::ffi::gpointer,
104 ) {
105 let f: &F = &*(f as *const F);
106 f(TlsFileDatabase::from_glib_borrow(this).unsafe_cast_ref())
107 }
108 unsafe {
109 let f: Box_<F> = Box_::new(f);
110 connect_raw(
111 self.as_ptr() as *mut _,
112 b"notify::anchors\0".as_ptr() as *const _,
113 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
114 notify_anchors_trampoline::<Self, F> as *const (),
115 )),
116 Box_::into_raw(f),
117 )
118 }
119 }
120}
121
122impl<O: IsA<TlsFileDatabase>> TlsFileDatabaseExt for O {}