summaryrefslogtreecommitdiff
path: root/gio/src/tlscertificate.hg
blob: 4b1af5ab0ca8c2f9a0d541a998a69f3a10b372f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* Copyright (C) 2012 The giomm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

_CONFIGINCLUDE(giommconfig.h)

#include <glibmm/object.h>
#include <giomm/enums.h>

_DEFS(giomm,gio)
_PINCLUDE(glibmm/private/object_p.h)

namespace Glib
{

// Forward declaration.
class GLIBMM_API ByteArray;

}

namespace Gio
{

class GIOMM_API SocketConnectable;

/** TlsCertificate - TLS certificate.
 * A certificate used for TLS authentication and encryption. This can represent
 * either a certificate only (eg, the certificate received by a client from a
 * server), or the combination of a certificate and a private key (which is
 * needed when acting as a TlsServerConnection).
 * @newin{2,36}
 */
class GIOMM_API TlsCertificate : public Glib::Object
{
  _CLASS_GOBJECT(TlsCertificate, GTlsCertificate, G_TLS_CERTIFICATE, Glib::Object, GObject, , , GIOMM_API)

protected:
  _WRAP_CTOR(TlsCertificate(const std::string& data, gssize length), g_tls_certificate_new_from_pem, errthrow)
  _WRAP_CTOR(TlsCertificate(const std::string& file), g_tls_certificate_new_from_file, errthrow)
  _WRAP_CTOR(TlsCertificate(const std::string& cert_file, const std::string& key_file), g_tls_certificate_new_from_files, errthrow)

public:
  _WRAP_METHOD_DOCS_ONLY(g_tls_certificate_new_from_pem)
  static Glib::RefPtr<TlsCertificate>
    create_from_pem(const std::string& data, gssize length = -1);

  _WRAP_METHOD_DOCS_ONLY(g_tls_certificate_new_from_file)
  _WRAP_CREATE(const std::string& file)

  _WRAP_METHOD_DOCS_ONLY(g_tls_certificate_new_from_files)
  _WRAP_CREATE(const std::string& cert_file, const std::string& key_file)

#m4 _CONVERSION(`GList*', `std::vector< Glib::RefPtr<TlsCertificate> >', `Glib::ListHandler< Glib::RefPtr<TlsCertificate> >::list_to_vector($3, Glib::OWNERSHIP_DEEP)')
  _WRAP_METHOD(static std::vector< Glib::RefPtr<TlsCertificate> > create_list_from_file(const std::string& file), g_tls_certificate_list_new_from_file, errthrow)

  _WRAP_METHOD(Glib::RefPtr<TlsCertificate> get_issuer(), g_tls_certificate_get_issuer, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const TlsCertificate> get_issuer() const, g_tls_certificate_get_issuer, constversion)

  _WRAP_METHOD(TlsCertificateFlags verify(const Glib::RefPtr<const SocketConnectable>& identity{?}, const Glib::RefPtr<const TlsCertificate>& trusted_ca{?}) const, g_tls_certificate_verify)
  _WRAP_METHOD(bool is_same(const Glib::RefPtr<const TlsCertificate>& cert_two) const, g_tls_certificate_is_same)

  _WRAP_PROPERTY("certificate", Glib::RefPtr<Glib::ByteArray>)
  _WRAP_PROPERTY("certificate-pem", std::string)
  _WRAP_PROPERTY("issuer", Glib::RefPtr<TlsCertificate>)

  // Write-only and construct-only
  //_WRAP_PROPERTY("private-key", Glib::RefPtr<Glib::ByteArray>)

  // Write-only and construct-only
  //_WRAP_PROPERTY("private-key-pem", std::string)

protected:
#m4 _CONVERSION(`GSocketConnectable*',`const Glib::RefPtr<const SocketConnectable>&',`Glib::wrap($3, true)')
#m4 _CONVERSION(`GTlsCertificate*',`const Glib::RefPtr<const TlsCertificate>&',`Glib::wrap($3, true)')
  _WRAP_VFUNC(TlsCertificateFlags verify(const Glib::RefPtr<const SocketConnectable>& identity, const Glib::RefPtr<const TlsCertificate>& trusted_ca) const, "verify")
};

} // namespace Gio