Some checks failed
Secrets v3 CI / 检查 (push) Has been cancelled
- Add apps/api, desktop Tauri shell, domain/application/crypto/device-auth/infrastructure-db - Replace desktop-daemon vault integration; drop secrets-core and secrets-mcp* - Ignore apps/desktop/dist and generated Tauri icons; document icon/dist steps in AGENTS.md - Apply rustfmt; fix clippy (collapsible_if, HTTP method as str)
28 lines
728 B
Rust
28 lines
728 B
Rust
use anyhow::{Context, Result};
|
|
use rand::{Rng, RngExt};
|
|
use sha2::{Digest, Sha256};
|
|
use url::Url;
|
|
|
|
pub fn loopback_redirect_uri(port: u16) -> Result<Url> {
|
|
Url::parse(&format!("http://127.0.0.1:{port}/oauth/callback"))
|
|
.context("failed to build loopback redirect URI")
|
|
}
|
|
|
|
pub fn new_device_fingerprint() -> String {
|
|
let mut bytes = [0_u8; 16];
|
|
rand::rng().fill(&mut bytes);
|
|
hex::encode(bytes)
|
|
}
|
|
|
|
pub fn new_device_login_token() -> String {
|
|
let mut bytes = [0_u8; 32];
|
|
rand::rng().fill_bytes(&mut bytes);
|
|
hex::encode(bytes)
|
|
}
|
|
|
|
pub fn hash_device_login_token(token: &str) -> String {
|
|
let mut hasher = Sha256::new();
|
|
hasher.update(token.as_bytes());
|
|
hex::encode(hasher.finalize())
|
|
}
|