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 
5 use crate::SocketConnectable;
6 use crate::TlsCertificateFlags;
7 use glib::object::IsA;
8 use glib::translate::*;
9 use glib::StaticType;
10 use std::fmt;
11 use std::ptr;
12 
13 glib::wrapper! {
14     #[doc(alias = "GTlsCertificate")]
15     pub struct TlsCertificate(Object<ffi::GTlsCertificate, ffi::GTlsCertificateClass>);
16 
17     match fn {
18         type_ => || ffi::g_tls_certificate_get_type(),
19     }
20 }
21 
22 impl TlsCertificate {
23     #[doc(alias = "g_tls_certificate_new_from_file")]
24     #[doc(alias = "new_from_file")]
from_file<P: AsRef<std::path::Path>>(file: P) -> Result<TlsCertificate, glib::Error>25     pub fn from_file<P: AsRef<std::path::Path>>(file: P) -> Result<TlsCertificate, glib::Error> {
26         unsafe {
27             let mut error = ptr::null_mut();
28             let ret =
29                 ffi::g_tls_certificate_new_from_file(file.as_ref().to_glib_none().0, &mut error);
30             if error.is_null() {
31                 Ok(from_glib_full(ret))
32             } else {
33                 Err(from_glib_full(error))
34             }
35         }
36     }
37 
38     #[doc(alias = "g_tls_certificate_new_from_files")]
39     #[doc(alias = "new_from_files")]
from_files<P: AsRef<std::path::Path>, Q: AsRef<std::path::Path>>( cert_file: P, key_file: Q, ) -> Result<TlsCertificate, glib::Error>40     pub fn from_files<P: AsRef<std::path::Path>, Q: AsRef<std::path::Path>>(
41         cert_file: P,
42         key_file: Q,
43     ) -> Result<TlsCertificate, glib::Error> {
44         unsafe {
45             let mut error = ptr::null_mut();
46             let ret = ffi::g_tls_certificate_new_from_files(
47                 cert_file.as_ref().to_glib_none().0,
48                 key_file.as_ref().to_glib_none().0,
49                 &mut error,
50             );
51             if error.is_null() {
52                 Ok(from_glib_full(ret))
53             } else {
54                 Err(from_glib_full(error))
55             }
56         }
57     }
58 
59     #[doc(alias = "g_tls_certificate_new_from_pem")]
60     #[doc(alias = "new_from_pem")]
from_pem(data: &str) -> Result<TlsCertificate, glib::Error>61     pub fn from_pem(data: &str) -> Result<TlsCertificate, glib::Error> {
62         let length = data.len() as isize;
63         unsafe {
64             let mut error = ptr::null_mut();
65             let ret =
66                 ffi::g_tls_certificate_new_from_pem(data.to_glib_none().0, length, &mut error);
67             if error.is_null() {
68                 Ok(from_glib_full(ret))
69             } else {
70                 Err(from_glib_full(error))
71             }
72         }
73     }
74 
75     #[doc(alias = "g_tls_certificate_list_new_from_file")]
list_new_from_file<P: AsRef<std::path::Path>>( file: P, ) -> Result<Vec<TlsCertificate>, glib::Error>76     pub fn list_new_from_file<P: AsRef<std::path::Path>>(
77         file: P,
78     ) -> Result<Vec<TlsCertificate>, glib::Error> {
79         unsafe {
80             let mut error = ptr::null_mut();
81             let ret = ffi::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 
94 pub const NONE_TLS_CERTIFICATE: Option<&TlsCertificate> = None;
95 
96 pub trait TlsCertificateExt: 'static {
97     #[doc(alias = "g_tls_certificate_get_issuer")]
98     #[doc(alias = "get_issuer")]
issuer(&self) -> Option<TlsCertificate>99     fn issuer(&self) -> Option<TlsCertificate>;
100 
101     #[doc(alias = "g_tls_certificate_is_same")]
is_same<P: IsA<TlsCertificate>>(&self, cert_two: &P) -> bool102     fn is_same<P: IsA<TlsCertificate>>(&self, cert_two: &P) -> bool;
103 
104     #[doc(alias = "g_tls_certificate_verify")]
verify<P: IsA<SocketConnectable>, Q: IsA<TlsCertificate>>( &self, identity: Option<&P>, trusted_ca: Option<&Q>, ) -> TlsCertificateFlags105     fn verify<P: IsA<SocketConnectable>, Q: IsA<TlsCertificate>>(
106         &self,
107         identity: Option<&P>,
108         trusted_ca: Option<&Q>,
109     ) -> TlsCertificateFlags;
110 
certificate(&self) -> Option<glib::ByteArray>111     fn certificate(&self) -> Option<glib::ByteArray>;
112 
113     #[doc(alias = "certificate-pem")]
certificate_pem(&self) -> Option<glib::GString>114     fn certificate_pem(&self) -> Option<glib::GString>;
115 }
116 
117 impl<O: IsA<TlsCertificate>> TlsCertificateExt for O {
issuer(&self) -> Option<TlsCertificate>118     fn issuer(&self) -> Option<TlsCertificate> {
119         unsafe {
120             from_glib_none(ffi::g_tls_certificate_get_issuer(
121                 self.as_ref().to_glib_none().0,
122             ))
123         }
124     }
125 
is_same<P: IsA<TlsCertificate>>(&self, cert_two: &P) -> bool126     fn is_same<P: IsA<TlsCertificate>>(&self, cert_two: &P) -> bool {
127         unsafe {
128             from_glib(ffi::g_tls_certificate_is_same(
129                 self.as_ref().to_glib_none().0,
130                 cert_two.as_ref().to_glib_none().0,
131             ))
132         }
133     }
134 
verify<P: IsA<SocketConnectable>, Q: IsA<TlsCertificate>>( &self, identity: Option<&P>, trusted_ca: Option<&Q>, ) -> TlsCertificateFlags135     fn verify<P: IsA<SocketConnectable>, Q: IsA<TlsCertificate>>(
136         &self,
137         identity: Option<&P>,
138         trusted_ca: Option<&Q>,
139     ) -> TlsCertificateFlags {
140         unsafe {
141             from_glib(ffi::g_tls_certificate_verify(
142                 self.as_ref().to_glib_none().0,
143                 identity.map(|p| p.as_ref()).to_glib_none().0,
144                 trusted_ca.map(|p| p.as_ref()).to_glib_none().0,
145             ))
146         }
147     }
148 
certificate(&self) -> Option<glib::ByteArray>149     fn certificate(&self) -> Option<glib::ByteArray> {
150         unsafe {
151             let mut value = glib::Value::from_type(<glib::ByteArray as StaticType>::static_type());
152             glib::gobject_ffi::g_object_get_property(
153                 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
154                 b"certificate\0".as_ptr() as *const _,
155                 value.to_glib_none_mut().0,
156             );
157             value
158                 .get()
159                 .expect("Return Value for property `certificate` getter")
160         }
161     }
162 
certificate_pem(&self) -> Option<glib::GString>163     fn certificate_pem(&self) -> Option<glib::GString> {
164         unsafe {
165             let mut value = glib::Value::from_type(<glib::GString as StaticType>::static_type());
166             glib::gobject_ffi::g_object_get_property(
167                 self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
168                 b"certificate-pem\0".as_ptr() as *const _,
169                 value.to_glib_none_mut().0,
170             );
171             value
172                 .get()
173                 .expect("Return Value for property `certificate-pem` getter")
174         }
175     }
176 }
177 
178 impl fmt::Display for TlsCertificate {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result179     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
180         f.write_str("TlsCertificate")
181     }
182 }
183