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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::{prelude::*, translate::*};

/// Flags which determine which parts of the #SecretBackend are initialized.
#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "SecretBackendFlags")]
pub enum BackendFlags {
    /// no flags for initializing the #SecretBackend
    #[doc(alias = "SECRET_BACKEND_NONE")]
    None,
    /// establish a session for transfer of secrets
    ///   while initializing the #SecretBackend
    #[doc(alias = "SECRET_BACKEND_OPEN_SESSION")]
    OpenSession,
    /// load collections while initializing the
    ///   #SecretBackend
    #[doc(alias = "SECRET_BACKEND_LOAD_COLLECTIONS")]
    LoadCollections,
    #[doc(hidden)]
    __Unknown(i32),
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
#[doc(hidden)]
impl IntoGlib for BackendFlags {
    type GlibType = ffi::SecretBackendFlags;

    #[inline]
    fn into_glib(self) -> ffi::SecretBackendFlags {
        match self {
            Self::None => ffi::SECRET_BACKEND_NONE,
            Self::OpenSession => ffi::SECRET_BACKEND_OPEN_SESSION,
            Self::LoadCollections => ffi::SECRET_BACKEND_LOAD_COLLECTIONS,
            Self::__Unknown(value) => value,
        }
    }
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
#[doc(hidden)]
impl FromGlib<ffi::SecretBackendFlags> for BackendFlags {
    #[inline]
    unsafe fn from_glib(value: ffi::SecretBackendFlags) -> Self {
        match value {
            ffi::SECRET_BACKEND_NONE => Self::None,
            ffi::SECRET_BACKEND_OPEN_SESSION => Self::OpenSession,
            ffi::SECRET_BACKEND_LOAD_COLLECTIONS => Self::LoadCollections,
            value => Self::__Unknown(value),
        }
    }
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
impl StaticType for BackendFlags {
    #[inline]
    #[doc(alias = "secret_backend_flags_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::secret_backend_flags_get_type()) }
    }
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
impl glib::HasParamSpec for BackendFlags {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
impl glib::value::ValueType for BackendFlags {
    type Type = Self;
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
unsafe impl<'a> glib::value::FromValue<'a> for BackendFlags {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
impl ToValue for BackendFlags {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

#[cfg(feature = "v0_19")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_19")))]
impl From<BackendFlags> for glib::Value {
    #[inline]
    fn from(v: BackendFlags) -> Self {
        ToValue::to_value(&v)
    }
}

/// Errors returned by the Secret Service.
///
/// None of the errors are appropriate for display to the user. It is up to the
/// application to handle them appropriately.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "SecretError")]
pub enum Error {
    /// received an invalid data or message from the Secret
    ///   Service
    #[doc(alias = "SECRET_ERROR_PROTOCOL")]
    Protocol,
    /// the item or collection is locked and the operation
    ///   cannot be performed
    #[doc(alias = "SECRET_ERROR_IS_LOCKED")]
    IsLocked,
    /// no such item or collection found in the Secret
    ///   Service
    #[doc(alias = "SECRET_ERROR_NO_SUCH_OBJECT")]
    NoSuchObject,
    /// a relevant item or collection already exists
    #[doc(alias = "SECRET_ERROR_ALREADY_EXISTS")]
    AlreadyExists,
    /// the file format is not valid
    #[doc(alias = "SECRET_ERROR_INVALID_FILE_FORMAT")]
    InvalidFileFormat,
    /// the xdg:schema attribute of the table does not match the schema name
    #[cfg(feature = "v0_21_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))]
    #[doc(alias = "SECRET_ERROR_MISMATCHED_SCHEMA")]
    MismatchedSchema,
    /// attribute contained in table not found in corresponding schema
    #[cfg(feature = "v0_21_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))]
    #[doc(alias = "SECRET_ERROR_NO_MATCHING_ATTRIBUTE")]
    NoMatchingAttribute,
    /// attribute could not be parsed according to its type reported in the table's
    /// schema
    #[cfg(feature = "v0_21_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))]
    #[doc(alias = "SECRET_ERROR_WRONG_TYPE")]
    WrongType,
    /// attribute list passed to secret_attributes_validate has no elements to
    /// validate
    #[cfg(feature = "v0_21_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v0_21_2")))]
    #[doc(alias = "SECRET_ERROR_EMPTY_TABLE")]
    EmptyTable,
    #[doc(hidden)]
    __Unknown(i32),
}

#[doc(hidden)]
impl IntoGlib for Error {
    type GlibType = ffi::SecretError;

    #[inline]
    fn into_glib(self) -> ffi::SecretError {
        match self {
            Self::Protocol => ffi::SECRET_ERROR_PROTOCOL,
            Self::IsLocked => ffi::SECRET_ERROR_IS_LOCKED,
            Self::NoSuchObject => ffi::SECRET_ERROR_NO_SUCH_OBJECT,
            Self::AlreadyExists => ffi::SECRET_ERROR_ALREADY_EXISTS,
            Self::InvalidFileFormat => ffi::SECRET_ERROR_INVALID_FILE_FORMAT,
            #[cfg(feature = "v0_21_2")]
            Self::MismatchedSchema => ffi::SECRET_ERROR_MISMATCHED_SCHEMA,
            #[cfg(feature = "v0_21_2")]
            Self::NoMatchingAttribute => ffi::SECRET_ERROR_NO_MATCHING_ATTRIBUTE,
            #[cfg(feature = "v0_21_2")]
            Self::WrongType => ffi::SECRET_ERROR_WRONG_TYPE,
            #[cfg(feature = "v0_21_2")]
            Self::EmptyTable => ffi::SECRET_ERROR_EMPTY_TABLE,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::SecretError> for Error {
    #[inline]
    unsafe fn from_glib(value: ffi::SecretError) -> Self {
        match value {
            ffi::SECRET_ERROR_PROTOCOL => Self::Protocol,
            ffi::SECRET_ERROR_IS_LOCKED => Self::IsLocked,
            ffi::SECRET_ERROR_NO_SUCH_OBJECT => Self::NoSuchObject,
            ffi::SECRET_ERROR_ALREADY_EXISTS => Self::AlreadyExists,
            ffi::SECRET_ERROR_INVALID_FILE_FORMAT => Self::InvalidFileFormat,
            #[cfg(feature = "v0_21_2")]
            ffi::SECRET_ERROR_MISMATCHED_SCHEMA => Self::MismatchedSchema,
            #[cfg(feature = "v0_21_2")]
            ffi::SECRET_ERROR_NO_MATCHING_ATTRIBUTE => Self::NoMatchingAttribute,
            #[cfg(feature = "v0_21_2")]
            ffi::SECRET_ERROR_WRONG_TYPE => Self::WrongType,
            #[cfg(feature = "v0_21_2")]
            ffi::SECRET_ERROR_EMPTY_TABLE => Self::EmptyTable,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for Error {
    #[inline]
    #[doc(alias = "secret_error_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::secret_error_get_type()) }
    }
}

impl glib::HasParamSpec for Error {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

impl glib::value::ValueType for Error {
    type Type = Self;
}

unsafe impl<'a> glib::value::FromValue<'a> for Error {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for Error {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

impl From<Error> for glib::Value {
    #[inline]
    fn from(v: Error) -> Self {
        ToValue::to_value(&v)
    }
}

/// The type of an attribute in a `SecretSchema`.
///
/// Attributes are stored as strings in the Secret Service, and the attribute
/// types simply define standard ways to store integer and boolean values as
/// strings.
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "SecretSchemaAttributeType")]
pub enum SchemaAttributeType {
    /// a utf-8 string attribute
    #[doc(alias = "SECRET_SCHEMA_ATTRIBUTE_STRING")]
    String,
    /// an integer attribute, stored as a decimal
    #[doc(alias = "SECRET_SCHEMA_ATTRIBUTE_INTEGER")]
    Integer,
    /// a boolean attribute, stored as 'true' or 'false'
    #[doc(alias = "SECRET_SCHEMA_ATTRIBUTE_BOOLEAN")]
    Boolean,
    #[doc(hidden)]
    __Unknown(i32),
}

#[doc(hidden)]
impl IntoGlib for SchemaAttributeType {
    type GlibType = ffi::SecretSchemaAttributeType;

    #[inline]
    fn into_glib(self) -> ffi::SecretSchemaAttributeType {
        match self {
            Self::String => ffi::SECRET_SCHEMA_ATTRIBUTE_STRING,
            Self::Integer => ffi::SECRET_SCHEMA_ATTRIBUTE_INTEGER,
            Self::Boolean => ffi::SECRET_SCHEMA_ATTRIBUTE_BOOLEAN,
            Self::__Unknown(value) => value,
        }
    }
}

#[doc(hidden)]
impl FromGlib<ffi::SecretSchemaAttributeType> for SchemaAttributeType {
    #[inline]
    unsafe fn from_glib(value: ffi::SecretSchemaAttributeType) -> Self {
        match value {
            ffi::SECRET_SCHEMA_ATTRIBUTE_STRING => Self::String,
            ffi::SECRET_SCHEMA_ATTRIBUTE_INTEGER => Self::Integer,
            ffi::SECRET_SCHEMA_ATTRIBUTE_BOOLEAN => Self::Boolean,
            value => Self::__Unknown(value),
        }
    }
}

impl StaticType for SchemaAttributeType {
    #[inline]
    #[doc(alias = "secret_schema_attribute_type_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::secret_schema_attribute_type_get_type()) }
    }
}

impl glib::HasParamSpec for SchemaAttributeType {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

impl glib::value::ValueType for SchemaAttributeType {
    type Type = Self;
}

unsafe impl<'a> glib::value::FromValue<'a> for SchemaAttributeType {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

impl ToValue for SchemaAttributeType {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

impl From<SchemaAttributeType> for glib::Value {
    #[inline]
    fn from(v: SchemaAttributeType) -> Self {
        ToValue::to_value(&v)
    }
}

/// Different types of schemas for storing secrets, intended for use with
/// [`schema()`][crate::schema()].
///
/// ## @SECRET_SCHEMA_NOTE
///
/// A predefined schema for personal passwords stored by the user in the
/// password manager. This schema has no attributes, and the items are not
/// meant to be used automatically by applications.
///
/// When used to search for items using this schema, it will only match
/// items that have the same schema. Items stored via libgnome-keyring with the
/// `GNOME_KEYRING_ITEM_NOTE` item type will match.
///
/// ## @SECRET_SCHEMA_COMPAT_NETWORK
///
/// A predefined schema that is compatible with items stored via the
/// libgnome-keyring 'network password' functions. This is meant to be used by
/// applications migrating from libgnome-keyring which stored their secrets as
/// 'network passwords'. It is not recommended that new code use this schema.
///
/// When used to search for items using this schema, it will only match
/// items that have the same schema. Items stored via libgnome-keyring with the
/// `GNOME_KEYRING_ITEM_NETWORK_PASSWORD` item type will match.
///
/// The following attributes exist in the schema:
///
/// ### Attributes:
///
/// <table>
///     <tr>
///         <td><tt>user</tt>:</td>
///         <td>The user name (string).</td>
///     </tr>
///     <tr>
///         <td><tt>domain</tt>:</td>
///         <td>The login domain or realm (string).</td></tr>
///     <tr>
///         <td><tt>object</tt>:</td>
///         <td>The object or path (string).</td>
///     </tr>
///     <tr>
///         <td><tt>protocol</tt>:</td>
///         <td>The protocol (a string like 'http').</td>
///     </tr>
///     <tr>
///         <td><tt>port</tt>:</td>
///         <td>The network port (integer).</td>
///     </tr>
///     <tr>
///         <td><tt>server</tt>:</td>
///         <td>The hostname or server (string).</td>
///     </tr>
///     <tr>
///         <td><tt>authtype</tt>:</td>
///         <td>The authentication type (string).</td>
///     </tr>
/// </table>
#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "SecretSchemaType")]
pub enum SchemaType {
    /// Personal passwords
    #[doc(alias = "SECRET_SCHEMA_TYPE_NOTE")]
    Note,
    /// Network passwords from older
    ///    libgnome-keyring storage
    #[doc(alias = "SECRET_SCHEMA_TYPE_COMPAT_NETWORK")]
    CompatNetwork,
    #[doc(hidden)]
    __Unknown(i32),
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
#[doc(hidden)]
impl IntoGlib for SchemaType {
    type GlibType = ffi::SecretSchemaType;

    #[inline]
    fn into_glib(self) -> ffi::SecretSchemaType {
        match self {
            Self::Note => ffi::SECRET_SCHEMA_TYPE_NOTE,
            Self::CompatNetwork => ffi::SECRET_SCHEMA_TYPE_COMPAT_NETWORK,
            Self::__Unknown(value) => value,
        }
    }
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
#[doc(hidden)]
impl FromGlib<ffi::SecretSchemaType> for SchemaType {
    #[inline]
    unsafe fn from_glib(value: ffi::SecretSchemaType) -> Self {
        match value {
            ffi::SECRET_SCHEMA_TYPE_NOTE => Self::Note,
            ffi::SECRET_SCHEMA_TYPE_COMPAT_NETWORK => Self::CompatNetwork,
            value => Self::__Unknown(value),
        }
    }
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
impl StaticType for SchemaType {
    #[inline]
    #[doc(alias = "secret_schema_type_get_type")]
    fn static_type() -> glib::Type {
        unsafe { from_glib(ffi::secret_schema_type_get_type()) }
    }
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
impl glib::HasParamSpec for SchemaType {
    type ParamSpec = glib::ParamSpecEnum;
    type SetValue = Self;
    type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;

    fn param_spec_builder() -> Self::BuilderFn {
        Self::ParamSpec::builder_with_default
    }
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
impl glib::value::ValueType for SchemaType {
    type Type = Self;
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
unsafe impl<'a> glib::value::FromValue<'a> for SchemaType {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    #[inline]
    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
    }
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
impl ToValue for SchemaType {
    #[inline]
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
        }
        value
    }

    #[inline]
    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}

#[cfg(feature = "v0_18_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v0_18_6")))]
impl From<SchemaType> for glib::Value {
    #[inline]
    fn from(v: SchemaType) -> Self {
        ToValue::to_value(&v)
    }
}