Skip to main content

veloren_voxygen_credentialstore/
lib.rs

1mod fake;
2#[cfg(target_os = "linux")] mod linux;
3
4use thiserror::Error;
5
6#[cfg(not(target_os = "linux"))]
7pub type SecureService = fake::SecretService;
8#[cfg(target_os = "linux")]
9pub type SecureService = linux::SecretService;
10
11pub struct Credentials {
12    pub auth_server: String,
13    pub username: String,
14    pub password: String,
15}
16
17#[derive(Debug, Error)]
18pub enum CredentialError {
19    #[error("Failed to connect to credential store")]
20    Connection,
21    #[error("Failed to get credential store collection")]
22    Collection,
23    #[error("Failed to determine credential store collection lock state")]
24    State,
25    #[error("Failed to search credentials in credential store")]
26    Search,
27    #[error("Failed to unlock stored credentials")]
28    Unlock,
29    #[error("No stored credentials found in credential store")]
30    Empty,
31    #[error("Failed to get stored credential secret")]
32    Secret,
33    #[error("Stored credential secret is not valid UTF-8")]
34    Utf8,
35    #[error("Failed to save credentials to credential store")]
36    Save,
37}
38
39#[derive(Clone, Copy, PartialEq, PartialOrd)]
40pub enum CredentialStatus {
41    /// Password manager isn't running yet (user can launch it later).
42    Disabled,
43    /// Password manager is running but locked (user can unlock it).
44    Locked,
45    /// Password manager is active and ready to use.
46    Ready,
47}
48
49pub trait CredentialStore {
50    /// Check if the credential store service is supported on this system.
51    fn is_supported(&self) -> bool;
52    /// Get the current service status.
53    fn status(&self) -> impl Future<Output = CredentialStatus>;
54    /// Load password for the specific user.
55    fn load(
56        &self,
57        auth_server: String,
58        username: String,
59    ) -> impl Future<Output = Result<String, CredentialError>>;
60    /// Save credentials.
61    fn save(&self, credentials: Credentials) -> impl Future<Output = Result<(), CredentialError>>;
62}