Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Failing after 5m32s
Podman Rootless Demo / deploy-prod (push) Has been skipped
65 lines
No EOL
1.8 KiB
Rust
65 lines
No EOL
1.8 KiB
Rust
//! Core abstractions for platform-agnostic cryptography and storage
|
|
|
|
use crate::domain::entities::*;
|
|
use crate::domain::error::DomainError;
|
|
|
|
/// Mnemonic generation trait
|
|
pub trait MnemonicGenerator {
|
|
type Error: Into<DomainError>;
|
|
|
|
fn generate(&self) -> Result<RecoveryPhrase, Self::Error>;
|
|
fn validate(&self, words: &[String]) -> Result<(), Self::Error>;
|
|
}
|
|
|
|
/// Key derivation trait
|
|
pub trait KeyDeriver {
|
|
type Error: Into<DomainError>;
|
|
|
|
fn derive_from_seed(&self, seed: &Seed) -> Result<(PublicKey, PrivateKey), Self::Error>;
|
|
fn derive_from_mnemonic(&self, mnemonic: &RecoveryPhrase, univ_id: &str) -> Result<Seed, Self::Error>;
|
|
}
|
|
|
|
/// File encryption trait
|
|
pub trait FileEncryptor {
|
|
type Error: Into<DomainError>;
|
|
|
|
fn encrypt(
|
|
&self,
|
|
seed: &Seed,
|
|
password: &str,
|
|
public_key: &PublicKey,
|
|
did: &Did,
|
|
univ_id: &str,
|
|
user_profiles: &[UserProfile],
|
|
) -> Result<PassportFile, Self::Error>;
|
|
|
|
fn decrypt(
|
|
&self,
|
|
file: &PassportFile,
|
|
password: &str,
|
|
) -> Result<(Seed, PublicKey, PrivateKey, Vec<UserProfile>), Self::Error>;
|
|
}
|
|
|
|
/// Storage trait for passport files
|
|
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait)]
|
|
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait(?Send))]
|
|
pub trait FileStorage {
|
|
type Error: Into<DomainError>;
|
|
|
|
async fn save(&self, file: &PassportFile, path: &str) -> Result<(), Self::Error>;
|
|
async fn load(&self, path: &str) -> Result<PassportFile, Self::Error>;
|
|
}
|
|
|
|
/// Random number generation trait
|
|
pub trait RngCore {
|
|
type Error: Into<DomainError>;
|
|
|
|
fn fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error>;
|
|
}
|
|
|
|
/// Time provider trait
|
|
pub trait TimeProvider {
|
|
type Error: Into<DomainError>;
|
|
|
|
fn now_seconds(&self) -> Result<u64, Self::Error>;
|
|
} |