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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/vhdirk/gir-files.git)
// DO NOT EDIT

#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use crate::CredentialPersistence;
#[cfg(any(feature = "v2_34", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
use glib::object::IsA;
use glib::translate::mut_override;
#[cfg(any(feature = "v2_2", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
use glib::translate::*;

glib::wrapper! {
    /// Groups information used for user authentication.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct Credential(Boxed<ffi::WebKitCredential>);

    match fn {
        copy => |ptr| ffi::webkit_credential_copy(mut_override(ptr)),
        free => |ptr| ffi::webkit_credential_free(ptr),
        type_ => || ffi::webkit_credential_get_type(),
    }
}

impl Credential {
    /// Create a new credential from the provided username, password and persistence mode.
    /// ## `username`
    /// The username for the new credential
    /// ## `password`
    /// The password for the new credential
    /// ## `persistence`
    /// The [`CredentialPersistence`][crate::CredentialPersistence] of the new credential
    ///
    /// # Returns
    ///
    /// A [`Credential`][crate::Credential].
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_credential_new")]
    pub fn new(username: &str, password: &str, persistence: CredentialPersistence) -> Credential {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::webkit_credential_new(
                username.to_glib_none().0,
                password.to_glib_none().0,
                persistence.into_glib(),
            ))
        }
    }

    /// Create a new credential from the `certificate` and persistence mode.
    ///
    /// Note that [`CredentialPersistence::Permanent`][crate::CredentialPersistence::Permanent] is not supported for certificate credentials.
    /// ## `certificate`
    /// The [`gio::TlsCertificate`][crate::gio::TlsCertificate], or [`None`]
    /// ## `persistence`
    /// The [`CredentialPersistence`][crate::CredentialPersistence] of the new credential
    ///
    /// # Returns
    ///
    /// A [`Credential`][crate::Credential].
    #[cfg(any(feature = "v2_34", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
    #[doc(alias = "webkit_credential_new_for_certificate")]
    #[doc(alias = "new_for_certificate")]
    pub fn for_certificate(
        certificate: Option<&impl IsA<gio::TlsCertificate>>,
        persistence: CredentialPersistence,
    ) -> Credential {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::webkit_credential_new_for_certificate(
                certificate.map(|p| p.as_ref()).to_glib_none().0,
                persistence.into_glib(),
            ))
        }
    }

    /// Create a new credential from the provided PIN and persistence mode.
    ///
    /// Note that [`CredentialPersistence::Permanent`][crate::CredentialPersistence::Permanent] is not supported for certificate pin credentials.
    /// ## `pin`
    /// The PIN for the new credential
    /// ## `persistence`
    /// The [`CredentialPersistence`][crate::CredentialPersistence] of the new credential
    ///
    /// # Returns
    ///
    /// A [`Credential`][crate::Credential].
    #[cfg(any(feature = "v2_34", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
    #[doc(alias = "webkit_credential_new_for_certificate_pin")]
    #[doc(alias = "new_for_certificate_pin")]
    pub fn for_certificate_pin(pin: &str, persistence: CredentialPersistence) -> Credential {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::webkit_credential_new_for_certificate_pin(
                pin.to_glib_none().0,
                persistence.into_glib(),
            ))
        }
    }

    /// Get the certificate currently held by this [`Credential`][crate::Credential].
    ///
    /// # Returns
    ///
    /// a [`gio::TlsCertificate`][crate::gio::TlsCertificate], or [`None`]
    #[cfg(any(feature = "v2_34", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_34")))]
    #[doc(alias = "webkit_credential_get_certificate")]
    #[doc(alias = "get_certificate")]
    pub fn certificate(&mut self) -> Option<gio::TlsCertificate> {
        unsafe {
            from_glib_none(ffi::webkit_credential_get_certificate(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Get the password currently held by this [`Credential`][crate::Credential].
    ///
    /// # Returns
    ///
    /// The password stored in the [`Credential`][crate::Credential].
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_credential_get_password")]
    #[doc(alias = "get_password")]
    pub fn password(&mut self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_credential_get_password(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Get the persistence mode currently held by this [`Credential`][crate::Credential].
    ///
    /// # Returns
    ///
    /// The [`CredentialPersistence`][crate::CredentialPersistence] stored in the [`Credential`][crate::Credential].
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_credential_get_persistence")]
    #[doc(alias = "get_persistence")]
    pub fn persistence(&mut self) -> CredentialPersistence {
        unsafe {
            from_glib(ffi::webkit_credential_get_persistence(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Get the username currently held by this [`Credential`][crate::Credential].
    ///
    /// # Returns
    ///
    /// The username stored in the [`Credential`][crate::Credential].
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_credential_get_username")]
    #[doc(alias = "get_username")]
    pub fn username(&mut self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::webkit_credential_get_username(
                self.to_glib_none_mut().0,
            ))
        }
    }

    /// Determine whether this credential has a password stored.
    ///
    /// # Returns
    ///
    /// [`true`] if the credential has a password or [`false`] otherwise.
    #[cfg(any(feature = "v2_2", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_2")))]
    #[doc(alias = "webkit_credential_has_password")]
    pub fn has_password(&mut self) -> bool {
        unsafe {
            from_glib(ffi::webkit_credential_has_password(
                self.to_glib_none_mut().0,
            ))
        }
    }
}