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

Method load_secret_key

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

Load the secret key for an identity.

(
        &self,
        id: &IdentityId,
        _password: Option<&str>,
    )

Source from the content-addressed store, hash-verified

541
542 /// Load the secret key for an identity.
543 pub fn load_secret_key(
544 &self,
545 id: &IdentityId,
546 _password: Option<&str>,
547 ) -> Result<SecretKey, IdentityError> {
548 let identity_dir = self.find_identity_dir(id)?;
549 let secret_path = identity_dir.join(Self::SECRET_KEY_FILE);
550
551 if !secret_path.exists() {
552 return Err(IdentityError::NotFound {
553 name: format!("secret key for {}", id.short()),
554 });
555 }
556
557 let content = fs::read_to_string(&secret_path)?;
558 let stored: StoredSecretKey = toml::from_str(&content)?;
559
560 if stored.encryption != "none" {
561 // TODO: Implement decryption
562 return Err(IdentityError::PasswordRequired);
563 }
564
565 let bytes = data_encoding::BASE64
566 .decode(stored.data.as_bytes())
567 .map_err(|_| IdentityError::InvalidKey("Invalid base64 in secret key".to_string()))?;
568
569 if bytes.len() != 32 {
570 return Err(IdentityError::InvalidKey(format!(
571 "Invalid secret key length: expected 32, got {}",
572 bytes.len()
573 )));
574 }
575
576 let mut arr = [0u8; 32];
577 arr.copy_from_slice(&bytes);
578 Ok(SecretKey::from_bytes(&arr))
579 }
580
581 /// Load a keypair for an identity.
582 pub fn load_keypair(

Callers 1

load_keypairMethod · 0.80

Calls 5

find_identity_dirMethod · 0.80
decodeMethod · 0.80
existsMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected