Skip to main content

webkit6/auto/
credential.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// from webkit-gir-files
4// DO NOT EDIT
5
6use crate::{CredentialPersistence, ffi};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    /// Groups information used for user authentication.
11    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12    pub struct Credential(Boxed<ffi::WebKitCredential>);
13
14    match fn {
15        copy => |ptr| ffi::webkit_credential_copy(mut_override(ptr)),
16        free => |ptr| ffi::webkit_credential_free(ptr),
17        type_ => || ffi::webkit_credential_get_type(),
18    }
19}
20
21impl Credential {
22    /// Create a new credential from the provided username, password and persistence mode.
23    /// ## `username`
24    /// The username for the new credential
25    /// ## `password`
26    /// The password for the new credential
27    /// ## `persistence`
28    /// The [`CredentialPersistence`][crate::CredentialPersistence] of the new credential
29    ///
30    /// # Returns
31    ///
32    /// A [`Credential`][crate::Credential].
33    #[doc(alias = "webkit_credential_new")]
34    pub fn new(username: &str, password: &str, persistence: CredentialPersistence) -> Credential {
35        assert_initialized_main_thread!();
36        unsafe {
37            from_glib_full(ffi::webkit_credential_new(
38                username.to_glib_none().0,
39                password.to_glib_none().0,
40                persistence.into_glib(),
41            ))
42        }
43    }
44
45    /// Create a new credential from the `certificate` and persistence mode.
46    ///
47    /// Note that [`CredentialPersistence::Permanent`][crate::CredentialPersistence::Permanent] is not supported for certificate credentials.
48    /// ## `certificate`
49    /// The [`gio::TlsCertificate`][crate::gio::TlsCertificate], or [`None`]
50    /// ## `persistence`
51    /// The [`CredentialPersistence`][crate::CredentialPersistence] of the new credential
52    ///
53    /// # Returns
54    ///
55    /// A [`Credential`][crate::Credential].
56    #[doc(alias = "webkit_credential_new_for_certificate")]
57    #[doc(alias = "new_for_certificate")]
58    pub fn for_certificate(
59        certificate: Option<&impl IsA<gio::TlsCertificate>>,
60        persistence: CredentialPersistence,
61    ) -> Credential {
62        assert_initialized_main_thread!();
63        unsafe {
64            from_glib_full(ffi::webkit_credential_new_for_certificate(
65                certificate.map(|p| p.as_ref()).to_glib_none().0,
66                persistence.into_glib(),
67            ))
68        }
69    }
70
71    /// Create a new credential from the provided PIN and persistence mode.
72    ///
73    /// Note that [`CredentialPersistence::Permanent`][crate::CredentialPersistence::Permanent] is not supported for certificate pin credentials.
74    /// ## `pin`
75    /// The PIN for the new credential
76    /// ## `persistence`
77    /// The [`CredentialPersistence`][crate::CredentialPersistence] of the new credential
78    ///
79    /// # Returns
80    ///
81    /// A [`Credential`][crate::Credential].
82    #[doc(alias = "webkit_credential_new_for_certificate_pin")]
83    #[doc(alias = "new_for_certificate_pin")]
84    pub fn for_certificate_pin(pin: &str, persistence: CredentialPersistence) -> Credential {
85        assert_initialized_main_thread!();
86        unsafe {
87            from_glib_full(ffi::webkit_credential_new_for_certificate_pin(
88                pin.to_glib_none().0,
89                persistence.into_glib(),
90            ))
91        }
92    }
93
94    /// Get the certificate currently held by this [`Credential`][crate::Credential].
95    ///
96    /// # Returns
97    ///
98    /// a [`gio::TlsCertificate`][crate::gio::TlsCertificate], or [`None`]
99    #[doc(alias = "webkit_credential_get_certificate")]
100    #[doc(alias = "get_certificate")]
101    pub fn certificate(&mut self) -> Option<gio::TlsCertificate> {
102        unsafe {
103            from_glib_none(ffi::webkit_credential_get_certificate(
104                self.to_glib_none_mut().0,
105            ))
106        }
107    }
108
109    /// Get the password currently held by this [`Credential`][crate::Credential].
110    ///
111    /// # Returns
112    ///
113    /// The password stored in the [`Credential`][crate::Credential].
114    #[doc(alias = "webkit_credential_get_password")]
115    #[doc(alias = "get_password")]
116    pub fn password(&mut self) -> Option<glib::GString> {
117        unsafe {
118            from_glib_none(ffi::webkit_credential_get_password(
119                self.to_glib_none_mut().0,
120            ))
121        }
122    }
123
124    /// Get the persistence mode currently held by this [`Credential`][crate::Credential].
125    ///
126    /// # Returns
127    ///
128    /// The [`CredentialPersistence`][crate::CredentialPersistence] stored in the [`Credential`][crate::Credential].
129    #[doc(alias = "webkit_credential_get_persistence")]
130    #[doc(alias = "get_persistence")]
131    pub fn persistence(&mut self) -> CredentialPersistence {
132        unsafe {
133            from_glib(ffi::webkit_credential_get_persistence(
134                self.to_glib_none_mut().0,
135            ))
136        }
137    }
138
139    /// Get the username currently held by this [`Credential`][crate::Credential].
140    ///
141    /// # Returns
142    ///
143    /// The username stored in the [`Credential`][crate::Credential].
144    #[doc(alias = "webkit_credential_get_username")]
145    #[doc(alias = "get_username")]
146    pub fn username(&mut self) -> Option<glib::GString> {
147        unsafe {
148            from_glib_none(ffi::webkit_credential_get_username(
149                self.to_glib_none_mut().0,
150            ))
151        }
152    }
153
154    /// Determine whether this credential has a password stored.
155    ///
156    /// # Returns
157    ///
158    /// [`true`] if the credential has a password or [`false`] otherwise.
159    #[doc(alias = "webkit_credential_has_password")]
160    pub fn has_password(&mut self) -> bool {
161        unsafe {
162            from_glib(ffi::webkit_credential_has_password(
163                self.to_glib_none_mut().0,
164            ))
165        }
166    }
167}