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
68/// Trait containing all [`struct@TlsFileDatabase`] methods.
69///
70/// # Implementors
71///
72/// [`TlsFileDatabase`][struct@crate::TlsFileDatabase]
73pub trait TlsFileDatabaseExt: IsA<TlsFileDatabase> + 'static {
74 /// The path to a file containing PEM encoded certificate authority
75 /// root anchors. The certificates in this file will be treated as
76 /// root authorities for the purpose of verifying other certificates
77 /// via the g_tls_database_verify_chain() operation.
78 fn anchors(&self) -> Option<glib::GString> {
79 ObjectExt::property(self.as_ref(), "anchors")
80 }
81
82 /// The path to a file containing PEM encoded certificate authority
83 /// root anchors. The certificates in this file will be treated as
84 /// root authorities for the purpose of verifying other certificates
85 /// via the g_tls_database_verify_chain() operation.
86 fn set_anchors(&self, anchors: Option<&str>) {
87 ObjectExt::set_property(self.as_ref(), "anchors", anchors)
88 }
89
90 #[doc(alias = "anchors")]
91 fn connect_anchors_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
92 unsafe extern "C" fn notify_anchors_trampoline<
93 P: IsA<TlsFileDatabase>,
94 F: Fn(&P) + 'static,
95 >(
96 this: *mut ffi::GTlsFileDatabase,
97 _param_spec: glib::ffi::gpointer,
98 f: glib::ffi::gpointer,
99 ) {
100 let f: &F = &*(f as *const F);
101 f(TlsFileDatabase::from_glib_borrow(this).unsafe_cast_ref())
102 }
103 unsafe {
104 let f: Box_<F> = Box_::new(f);
105 connect_raw(
106 self.as_ptr() as *mut _,
107 c"notify::anchors".as_ptr() as *const _,
108 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
109 notify_anchors_trampoline::<Self, F> as *const (),
110 )),
111 Box_::into_raw(f),
112 )
113 }
114 }
115}
116
117impl<O: IsA<TlsFileDatabase>> TlsFileDatabaseExt for O {}