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
// Generated by gir (https://github.com/gtk-rs/gir @ 0e476ab5c1de)
// from /usr/share/gir-1.0 (@ ???)
// DO NOT EDIT
use crate::Details;
use glib::translate::*;
glib::wrapper! {
/// This class represents the result you get when checking for an authorization.
///
/// # Implements
///
/// [`trait@glib::ObjectExt`]
#[doc(alias = "PolkitAuthorizationResult")]
pub struct AuthorizationResult(Object<ffi::PolkitAuthorizationResult, ffi::PolkitAuthorizationResultClass>);
match fn {
type_ => || ffi::polkit_authorization_result_get_type(),
}
}
impl AuthorizationResult {
/// Creates a new [`AuthorizationResult`][crate::AuthorizationResult] object.
/// ## `is_authorized`
/// Whether the subject is authorized.
/// ## `is_challenge`
/// Whether the subject is authorized if more
/// information is provided. Must be [`false`] unless `is_authorized` is
/// [`true`].
/// ## `details`
/// Must be [`None`] unless `is_authorized` is [`true`]
///
/// # Returns
///
/// A [`AuthorizationResult`][crate::AuthorizationResult] object. Free with `g_object_unref()`.
#[doc(alias = "polkit_authorization_result_new")]
pub fn new(
is_authorized: bool,
is_challenge: bool,
details: Option<&Details>,
) -> AuthorizationResult {
unsafe {
from_glib_full(ffi::polkit_authorization_result_new(
is_authorized.into_glib(),
is_challenge.into_glib(),
details.to_glib_none().0,
))
}
}
/// Gets the details about the result.
///
/// # Returns
///
/// A [`Details`][crate::Details] object or
/// [`None`] if there are no details. This object is owned by `self` and
/// should not be freed by the caller.
#[doc(alias = "polkit_authorization_result_get_details")]
#[doc(alias = "get_details")]
pub fn details(&self) -> Option<Details> {
unsafe {
from_glib_none(ffi::polkit_authorization_result_get_details(
self.to_glib_none().0,
))
}
}
/// Gets whether the authentication request was dismissed / canceled by the user.
///
/// This method simply reads the value of the key/value pair in `details` with the
/// key `<literal>`polkit.dismissed`</literal>`.
///
/// # Returns
///
/// [`true`] if the authentication request was dismissed, [`false`] otherwise.
#[cfg(feature = "v0_101")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_101")))]
#[doc(alias = "polkit_authorization_result_get_dismissed")]
#[doc(alias = "get_dismissed")]
pub fn is_dismissed(&self) -> bool {
unsafe {
from_glib(ffi::polkit_authorization_result_get_dismissed(
self.to_glib_none().0,
))
}
}
/// Gets whether the subject is authorized.
///
/// If the authorization is temporary, use [`temporary_authorization_id()`][Self::temporary_authorization_id()]
/// to get the opaque identifier for the temporary authorization.
///
/// # Returns
///
/// Whether the subject is authorized.
#[doc(alias = "polkit_authorization_result_get_is_authorized")]
#[doc(alias = "get_is_authorized")]
pub fn is_authorized(&self) -> bool {
unsafe {
from_glib(ffi::polkit_authorization_result_get_is_authorized(
self.to_glib_none().0,
))
}
}
/// Gets whether the subject is authorized if more information is provided.
///
/// # Returns
///
/// Whether the subject is authorized if more information is provided.
#[doc(alias = "polkit_authorization_result_get_is_challenge")]
#[doc(alias = "get_is_challenge")]
pub fn is_challenge(&self) -> bool {
unsafe {
from_glib(ffi::polkit_authorization_result_get_is_challenge(
self.to_glib_none().0,
))
}
}
/// Gets whether authorization is retained if obtained via authentication. This can only be the case
/// if `self` indicates that the subject can obtain authorization after challenge (cf.
/// [`is_challenge()`][Self::is_challenge()]), e.g. when the subject is not already authorized (cf.
/// [`is_authorized()`][Self::is_authorized()]).
///
/// If the subject is already authorized, use [`temporary_authorization_id()`][Self::temporary_authorization_id()]
/// to check if the authorization is temporary.
///
/// This method simply reads the value of the key/value pair in `details` with the
/// key `<literal>`polkit.retains_authorization_after_challenge`</literal>`.
///
/// # Returns
///
/// [`true`] if the authorization is or will be temporary.
#[doc(alias = "polkit_authorization_result_get_retains_authorization")]
#[doc(alias = "get_retains_authorization")]
pub fn is_retains_authorization(&self) -> bool {
unsafe {
from_glib(ffi::polkit_authorization_result_get_retains_authorization(
self.to_glib_none().0,
))
}
}
/// Gets the opaque temporary authorization id for `self` if `self` indicates the
/// subject is authorized and the authorization is temporary rather than one-shot or
/// permanent.
///
/// You can use this string together with the result from
/// [`Authority::enumerate_temporary_authorizations()`][crate::Authority::enumerate_temporary_authorizations()] to get more details
/// about the temporary authorization or [`Authority::revoke_temporary_authorization_by_id()`][crate::Authority::revoke_temporary_authorization_by_id()]
/// to revoke the temporary authorization.
///
/// If the subject is not authorized, use [`is_retains_authorization()`][Self::is_retains_authorization()]
/// to check if the authorization will be retained if obtained via authentication.
///
/// This method simply reads the value of the key/value pair in `details` with the
/// key `<literal>`polkit.temporary_authorization_id`</literal>`.
///
/// # Returns
///
/// The opaque temporary authorization id for
/// `self` or [`None`] if not available. Do not free this string, it
/// is owned by `self`.
#[doc(alias = "polkit_authorization_result_get_temporary_authorization_id")]
#[doc(alias = "get_temporary_authorization_id")]
pub fn temporary_authorization_id(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(
ffi::polkit_authorization_result_get_temporary_authorization_id(
self.to_glib_none().0,
),
)
}
}
}