gio/auto/
tls_certificate.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 gio_sys;
6use glib::object::IsA;
7use glib::translate::*;
8use glib::GString;
9use glib::StaticType;
10use glib::Value;
11use gobject_sys;
12use std;
13use std::fmt;
14use std::ptr;
15use Error;
16use SocketConnectable;
17use TlsCertificateFlags;
18
19glib_wrapper! {
20    pub struct TlsCertificate(Object<gio_sys::GTlsCertificate, gio_sys::GTlsCertificateClass, TlsCertificateClass>);
21
22    match fn {
23        get_type => || gio_sys::g_tls_certificate_get_type(),
24    }
25}
26
27impl TlsCertificate {
28    pub fn new_from_file<P: AsRef<std::path::Path>>(file: P) -> Result<TlsCertificate, Error> {
29        unsafe {
30            let mut error = ptr::null_mut();
31            let ret = gio_sys::g_tls_certificate_new_from_file(
32                file.as_ref().to_glib_none().0,
33                &mut error,
34            );
35            if error.is_null() {
36                Ok(from_glib_full(ret))
37            } else {
38                Err(from_glib_full(error))
39            }
40        }
41    }
42
43    pub fn new_from_files<P: AsRef<std::path::Path>, Q: AsRef<std::path::Path>>(
44        cert_file: P,
45        key_file: Q,
46    ) -> Result<TlsCertificate, Error> {
47        unsafe {
48            let mut error = ptr::null_mut();
49            let ret = gio_sys::g_tls_certificate_new_from_files(
50                cert_file.as_ref().to_glib_none().0,
51                key_file.as_ref().to_glib_none().0,
52                &mut error,
53            );
54            if error.is_null() {
55                Ok(from_glib_full(ret))
56            } else {
57                Err(from_glib_full(error))
58            }
59        }
60    }
61
62    pub fn new_from_pem(data: &str) -> Result<TlsCertificate, Error> {
63        let length = data.len() as isize;
64        unsafe {
65            let mut error = ptr::null_mut();
66            let ret =
67                gio_sys::g_tls_certificate_new_from_pem(data.to_glib_none().0, length, &mut error);
68            if error.is_null() {
69                Ok(from_glib_full(ret))
70            } else {
71                Err(from_glib_full(error))
72            }
73        }
74    }
75
76    pub fn list_new_from_file<P: AsRef<std::path::Path>>(
77        file: P,
78    ) -> Result<Vec<TlsCertificate>, Error> {
79        unsafe {
80            let mut error = ptr::null_mut();
81            let ret = gio_sys::g_tls_certificate_list_new_from_file(
82                file.as_ref().to_glib_none().0,
83                &mut error,
84            );
85            if error.is_null() {
86                Ok(FromGlibPtrContainer::from_glib_full(ret))
87            } else {
88                Err(from_glib_full(error))
89            }
90        }
91    }
92}
93
94pub const NONE_TLS_CERTIFICATE: Option<&TlsCertificate> = None;
95
96pub trait TlsCertificateExt: 'static {
97    fn get_issuer(&self) -> Option<TlsCertificate>;
98
99    fn is_same<P: IsA<TlsCertificate>>(&self, cert_two: &P) -> bool;
100
101    fn verify<P: IsA<SocketConnectable>, Q: IsA<TlsCertificate>>(
102        &self,
103        identity: Option<&P>,
104        trusted_ca: Option<&Q>,
105    ) -> TlsCertificateFlags;
106
107    //fn get_property_certificate(&self) -> /*Ignored*/Option<glib::ByteArray>;
108
109    fn get_property_certificate_pem(&self) -> Option<GString>;
110}
111
112impl<O: IsA<TlsCertificate>> TlsCertificateExt for O {
113    fn get_issuer(&self) -> Option<TlsCertificate> {
114        unsafe {
115            from_glib_none(gio_sys::g_tls_certificate_get_issuer(
116                self.as_ref().to_glib_none().0,
117            ))
118        }
119    }
120
121    fn is_same<P: IsA<TlsCertificate>>(&self, cert_two: &P) -> bool {
122        unsafe {
123            from_glib(gio_sys::g_tls_certificate_is_same(
124                self.as_ref().to_glib_none().0,
125                cert_two.as_ref().to_glib_none().0,
126            ))
127        }
128    }
129
130    fn verify<P: IsA<SocketConnectable>, Q: IsA<TlsCertificate>>(
131        &self,
132        identity: Option<&P>,
133        trusted_ca: Option<&Q>,
134    ) -> TlsCertificateFlags {
135        unsafe {
136            from_glib(gio_sys::g_tls_certificate_verify(
137                self.as_ref().to_glib_none().0,
138                identity.map(|p| p.as_ref()).to_glib_none().0,
139                trusted_ca.map(|p| p.as_ref()).to_glib_none().0,
140            ))
141        }
142    }
143
144    //fn get_property_certificate(&self) -> /*Ignored*/Option<glib::ByteArray> {
145    //    unsafe {
146    //        let mut value = Value::from_type(</*Unknown type*/ as StaticType>::static_type());
147    //        gobject_sys::g_object_get_property(self.to_glib_none().0 as *mut gobject_sys::GObject, b"certificate\0".as_ptr() as *const _, value.to_glib_none_mut().0);
148    //        value.get()
149    //    }
150    //}
151
152    fn get_property_certificate_pem(&self) -> Option<GString> {
153        unsafe {
154            let mut value = Value::from_type(<GString as StaticType>::static_type());
155            gobject_sys::g_object_get_property(
156                self.to_glib_none().0 as *mut gobject_sys::GObject,
157                b"certificate-pem\0".as_ptr() as *const _,
158                value.to_glib_none_mut().0,
159            );
160            value.get()
161        }
162    }
163}
164
165impl fmt::Display for TlsCertificate {
166    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
167        write!(f, "TlsCertificate")
168    }
169}