MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / save_secret_key

Method save_secret_key

atomic-identity/src/store.rs:479–519  ·  view source on GitHub ↗

Save a secret key (with optional encryption).

(
        &self,
        identity_dir: &Path,
        secret_key: &SecretKey,
        password: Option<&str>,
    )

Source from the content-addressed store, hash-verified

477
478 /// Save a secret key (with optional encryption).
479 fn save_secret_key(
480 &self,
481 identity_dir: &Path,
482 secret_key: &SecretKey,
483 password: Option<&str>,
484 ) -> Result<(), IdentityError> {
485 let secret_path = identity_dir.join(Self::SECRET_KEY_FILE);
486
487 if let Some(_password) = password {
488 // TODO: Implement proper password-based encryption
489 // For now, we'll store it with a marker that it should be encrypted
490 let stored = StoredSecretKey {
491 data: data_encoding::BASE64.encode(secret_key.as_bytes()),
492 encryption: "none".to_string(), // TODO: Change to "argon2id+chacha20poly1305"
493 salt: None,
494 nonce: None,
495 };
496 let content = toml::to_string_pretty(&stored)?;
497 fs::write(&secret_path, content)?;
498 } else {
499 // Store unencrypted (not recommended for production)
500 let stored = StoredSecretKey {
501 data: data_encoding::BASE64.encode(secret_key.as_bytes()),
502 encryption: "none".to_string(),
503 salt: None,
504 nonce: None,
505 };
506 let content = toml::to_string_pretty(&stored)?;
507 fs::write(&secret_path, content)?;
508 }
509
510 // Set restrictive permissions on Unix
511 #[cfg(unix)]
512 {
513 use std::os::unix::fs::PermissionsExt;
514 let permissions = fs::Permissions::from_mode(0o600);
515 fs::set_permissions(&secret_path, permissions)?;
516 }
517
518 Ok(())
519 }
520
521 /// Load an identity by ID.
522 pub fn load(&self, id: &IdentityId) -> Result<Identity, IdentityError> {

Callers 1

save_with_secretMethod · 0.80

Calls 4

set_permissionsFunction · 0.85
writeFunction · 0.50
encodeMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected