source: appstream-generator/build/girepo/gio/TlsCertificate.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 9.9 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.TlsCertificate;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.SocketConnectableIF;
26private import glib.ConstructionException;
27private import glib.ErrorG;
28private import glib.GException;
29private import glib.ListG;
30private import glib.Str;
31private import gobject.ObjectG;
32
33
34/**
35 * A certificate used for TLS authentication and encryption.
36 * This can represent either a certificate only (eg, the certificate
37 * received by a client from a server), or the combination of
38 * a certificate and a private key (which is needed when acting as a
39 * #GTlsServerConnection).
40 *
41 * Since: 2.28
42 */
43public class TlsCertificate : ObjectG
44{
45        /** the main Gtk struct */
46        protected GTlsCertificate* gTlsCertificate;
47
48        /** Get the main Gtk struct */
49        public GTlsCertificate* getTlsCertificateStruct()
50        {
51                return gTlsCertificate;
52        }
53
54        /** the main Gtk struct as a void* */
55        protected override void* getStruct()
56        {
57                return cast(void*)gTlsCertificate;
58        }
59
60        protected override void setStruct(GObject* obj)
61        {
62                gTlsCertificate = cast(GTlsCertificate*)obj;
63                super.setStruct(obj);
64        }
65
66        /**
67         * Sets our main struct and passes it to the parent class.
68         */
69        public this (GTlsCertificate* gTlsCertificate, bool ownedRef = false)
70        {
71                this.gTlsCertificate = gTlsCertificate;
72                super(cast(GObject*)gTlsCertificate, ownedRef);
73        }
74
75
76        /** */
77        public static GType getType()
78        {
79                return g_tls_certificate_get_type();
80        }
81
82        /**
83         * Creates a #GTlsCertificate from the PEM-encoded data in @file. The
84         * returned certificate will be the first certificate found in @file. As
85         * of GLib 2.44, if @file contains more certificates it will try to load
86         * a certificate chain. All certificates will be verified in the order
87         * found (top-level certificate should be the last one in the file) and
88         * the #GTlsCertificate:issuer property of each certificate will be set
89         * accordingly if the verification succeeds. If any certificate in the
90         * chain cannot be verified, the first certificate in the file will
91         * still be returned.
92         *
93         * If @file cannot be read or parsed, the function will return %NULL and
94         * set @error. Otherwise, this behaves like
95         * g_tls_certificate_new_from_pem().
96         *
97         * Params:
98         *     file = file containing a PEM-encoded certificate to import
99         *
100         * Returns: the new certificate, or %NULL on error
101         *
102         * Since: 2.28
103         *
104         * Throws: GException on failure.
105         * Throws: ConstructionException GTK+ fails to create the object.
106         */
107        public this(string file)
108        {
109                GError* err = null;
110               
111                auto p = g_tls_certificate_new_from_file(Str.toStringz(file), &err);
112               
113                if (err !is null)
114                {
115                        throw new GException( new ErrorG(err) );
116                }
117               
118                if(p is null)
119                {
120                        throw new ConstructionException("null returned by new_from_file");
121                }
122               
123                this(cast(GTlsCertificate*) p, true);
124        }
125
126        /**
127         * Creates a #GTlsCertificate from the PEM-encoded data in @cert_file
128         * and @key_file. The returned certificate will be the first certificate
129         * found in @cert_file. As of GLib 2.44, if @cert_file contains more
130         * certificates it will try to load a certificate chain. All
131         * certificates will be verified in the order found (top-level
132         * certificate should be the last one in the file) and the
133         * #GTlsCertificate:issuer property of each certificate will be set
134         * accordingly if the verification succeeds. If any certificate in the
135         * chain cannot be verified, the first certificate in the file will
136         * still be returned.
137         *
138         * If either file cannot be read or parsed, the function will return
139         * %NULL and set @error. Otherwise, this behaves like
140         * g_tls_certificate_new_from_pem().
141         *
142         * Params:
143         *     certFile = file containing one or more PEM-encoded certificates to
144         *         import
145         *     keyFile = file containing a PEM-encoded private key to import
146         *
147         * Returns: the new certificate, or %NULL on error
148         *
149         * Since: 2.28
150         *
151         * Throws: GException on failure.
152         * Throws: ConstructionException GTK+ fails to create the object.
153         */
154        public this(string certFile, string keyFile)
155        {
156                GError* err = null;
157               
158                auto p = g_tls_certificate_new_from_files(Str.toStringz(certFile), Str.toStringz(keyFile), &err);
159               
160                if (err !is null)
161                {
162                        throw new GException( new ErrorG(err) );
163                }
164               
165                if(p is null)
166                {
167                        throw new ConstructionException("null returned by new_from_files");
168                }
169               
170                this(cast(GTlsCertificate*) p, true);
171        }
172
173        /**
174         * Creates a #GTlsCertificate from the PEM-encoded data in @data. If
175         * @data includes both a certificate and a private key, then the
176         * returned certificate will include the private key data as well. (See
177         * the #GTlsCertificate:private-key-pem property for information about
178         * supported formats.)
179         *
180         * The returned certificate will be the first certificate found in
181         * @data. As of GLib 2.44, if @data contains more certificates it will
182         * try to load a certificate chain. All certificates will be verified in
183         * the order found (top-level certificate should be the last one in the
184         * file) and the #GTlsCertificate:issuer property of each certificate
185         * will be set accordingly if the verification succeeds. If any
186         * certificate in the chain cannot be verified, the first certificate in
187         * the file will still be returned.
188         *
189         * Params:
190         *     data = PEM-encoded certificate data
191         *     length = the length of @data, or -1 if it's 0-terminated.
192         *
193         * Returns: the new certificate, or %NULL if @data is invalid
194         *
195         * Since: 2.28
196         *
197         * Throws: GException on failure.
198         * Throws: ConstructionException GTK+ fails to create the object.
199         */
200        public this(string data, ptrdiff_t length)
201        {
202                GError* err = null;
203               
204                auto p = g_tls_certificate_new_from_pem(Str.toStringz(data), length, &err);
205               
206                if (err !is null)
207                {
208                        throw new GException( new ErrorG(err) );
209                }
210               
211                if(p is null)
212                {
213                        throw new ConstructionException("null returned by new_from_pem");
214                }
215               
216                this(cast(GTlsCertificate*) p, true);
217        }
218
219        /**
220         * Creates one or more #GTlsCertificates from the PEM-encoded
221         * data in @file. If @file cannot be read or parsed, the function will
222         * return %NULL and set @error. If @file does not contain any
223         * PEM-encoded certificates, this will return an empty list and not
224         * set @error.
225         *
226         * Params:
227         *     file = file containing PEM-encoded certificates to import
228         *
229         * Returns: a
230         *     #GList containing #GTlsCertificate objects. You must free the list
231         *     and its contents when you are done with it.
232         *
233         * Since: 2.28
234         *
235         * Throws: GException on failure.
236         */
237        public static ListG listNewFromFile(string file)
238        {
239                GError* err = null;
240               
241                auto p = g_tls_certificate_list_new_from_file(Str.toStringz(file), &err);
242               
243                if (err !is null)
244                {
245                        throw new GException( new ErrorG(err) );
246                }
247               
248                if(p is null)
249                {
250                        return null;
251                }
252               
253                return new ListG(cast(GList*) p, true);
254        }
255
256        /**
257         * Gets the #GTlsCertificate representing @cert's issuer, if known
258         *
259         * Returns: The certificate of @cert's issuer,
260         *     or %NULL if @cert is self-signed or signed with an unknown
261         *     certificate.
262         *
263         * Since: 2.28
264         */
265        public TlsCertificate getIssuer()
266        {
267                auto p = g_tls_certificate_get_issuer(gTlsCertificate);
268               
269                if(p is null)
270                {
271                        return null;
272                }
273               
274                return ObjectG.getDObject!(TlsCertificate)(cast(GTlsCertificate*) p);
275        }
276
277        /**
278         * Check if two #GTlsCertificate objects represent the same certificate.
279         * The raw DER byte data of the two certificates are checked for equality.
280         * This has the effect that two certificates may compare equal even if
281         * their #GTlsCertificate:issuer, #GTlsCertificate:private-key, or
282         * #GTlsCertificate:private-key-pem properties differ.
283         *
284         * Params:
285         *     certTwo = second certificate to compare
286         *
287         * Returns: whether the same or not
288         *
289         * Since: 2.34
290         */
291        public bool isSame(TlsCertificate certTwo)
292        {
293                return g_tls_certificate_is_same(gTlsCertificate, (certTwo is null) ? null : certTwo.getTlsCertificateStruct()) != 0;
294        }
295
296        /**
297         * This verifies @cert and returns a set of #GTlsCertificateFlags
298         * indicating any problems found with it. This can be used to verify a
299         * certificate outside the context of making a connection, or to
300         * check a certificate against a CA that is not part of the system
301         * CA database.
302         *
303         * If @identity is not %NULL, @cert's name(s) will be compared against
304         * it, and %G_TLS_CERTIFICATE_BAD_IDENTITY will be set in the return
305         * value if it does not match. If @identity is %NULL, that bit will
306         * never be set in the return value.
307         *
308         * If @trusted_ca is not %NULL, then @cert (or one of the certificates
309         * in its chain) must be signed by it, or else
310         * %G_TLS_CERTIFICATE_UNKNOWN_CA will be set in the return value. If
311         * @trusted_ca is %NULL, that bit will never be set in the return
312         * value.
313         *
314         * (All other #GTlsCertificateFlags values will always be set or unset
315         * as appropriate.)
316         *
317         * Params:
318         *     identity = the expected peer identity
319         *     trustedCa = the certificate of a trusted authority
320         *
321         * Returns: the appropriate #GTlsCertificateFlags
322         *
323         * Since: 2.28
324         */
325        public GTlsCertificateFlags verify(SocketConnectableIF identity, TlsCertificate trustedCa)
326        {
327                return g_tls_certificate_verify(gTlsCertificate, (identity is null) ? null : identity.getSocketConnectableStruct(), (trustedCa is null) ? null : trustedCa.getTlsCertificateStruct());
328        }
329}
Note: See TracBrowser for help on using the repository browser.