Generate a fresh server token: `(plaintext, hash)`. The plaintext is returned to the server once on register; only the hash is persisted.
()
| 401 | fn to_hex(bytes: &[u8]) -> String { |
| 402 | bytes.iter().map(|byte| format!("{byte:02x}")).collect() |
| 403 | } |
| 404 | |
| 405 | /// SHA-256 hex of a server token (what the DB stores; never the token itself). |
| 406 | pub fn token_hash(token: &str) -> String { |
| 407 | to_hex(&sha2::Sha256::digest(token.as_bytes())) |
| 408 | } |
| 409 | |
| 410 | /// Generate a fresh server token: `(plaintext, hash)`. The plaintext is returned to the |
| 411 | /// server once on register; only the hash is persisted. |
| 412 | pub fn issue_token() -> Result<(String, String)> { |
| 413 | let mut bytes = [0u8; 32]; |
no test coverage detected