style: apply cargo fmt across the crate (A20)
The repo never enforced rustfmt, so formatting had drifted broadly. This is a single mechanical `cargo fmt` pass over the whole crate (no behavioral change; lib suite green, 493 passed). Going forward fmt should be enforced (planned CI fmt --check step). Part of the 0.6.1 hygiene pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+11
-6
@@ -41,7 +41,8 @@ pub fn identity_path() -> Option<PathBuf> {
|
||||
/// A *missing* file (first ever run, or right after a reset) is the normal
|
||||
/// create path.
|
||||
pub fn load_or_create() -> Result<SecretKey> {
|
||||
let path = identity_path().context("could not determine a config directory for the identity key")?;
|
||||
let path =
|
||||
identity_path().context("could not determine a config directory for the identity key")?;
|
||||
load_or_create_at(&path)
|
||||
}
|
||||
|
||||
@@ -49,7 +50,8 @@ pub fn load_or_create() -> Result<SecretKey> {
|
||||
/// deliberate "Regenerate identity" / unlink action — the old id is discarded and
|
||||
/// unrecoverable, so callers should confirm with the user first.
|
||||
pub fn regenerate() -> Result<SecretKey> {
|
||||
let path = identity_path().context("could not determine a config directory for the identity key")?;
|
||||
let path =
|
||||
identity_path().context("could not determine a config directory for the identity key")?;
|
||||
let key = SecretKey::generate();
|
||||
save_at(&path, &key)?;
|
||||
Ok(key)
|
||||
@@ -57,7 +59,8 @@ pub fn regenerate() -> Result<SecretKey> {
|
||||
|
||||
/// Atomic, `0600` write at the default identity path. See [`save_at`].
|
||||
pub fn save(key: &SecretKey) -> Result<()> {
|
||||
let path = identity_path().context("could not determine a config directory for the identity key")?;
|
||||
let path =
|
||||
identity_path().context("could not determine a config directory for the identity key")?;
|
||||
save_at(&path, key)
|
||||
}
|
||||
|
||||
@@ -80,13 +83,15 @@ fn load_or_create_at(path: &std::path::Path) -> Result<SecretKey> {
|
||||
/// perms are applied before the rename so the secret is never briefly
|
||||
/// world-readable.
|
||||
fn save_at(path: &std::path::Path, key: &SecretKey) -> Result<()> {
|
||||
let parent = path.parent().context("identity path has no parent directory")?;
|
||||
let parent = path
|
||||
.parent()
|
||||
.context("identity path has no parent directory")?;
|
||||
fs::create_dir_all(parent).with_context(|| format!("failed to create {}", parent.display()))?;
|
||||
|
||||
let tmp = parent.join(format!(".identity.key.tmp.{}", std::process::id()));
|
||||
{
|
||||
let mut f =
|
||||
fs::File::create(&tmp).with_context(|| format!("failed to create {}", tmp.display()))?;
|
||||
let mut f = fs::File::create(&tmp)
|
||||
.with_context(|| format!("failed to create {}", tmp.display()))?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
Reference in New Issue
Block a user