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

Method run

atomic-cli/src/commands/memory/verify.rs:31–96  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

29
30impl Command for MemoryVerify {
31 fn run(&self) -> CliResult<()> {
32 let root = find_repository_root()?;
33 let repo = Repository::open(&root).map_err(CliError::Repository)?;
34
35 let inputs = bridge::read_memory(&repo, &self.id)?;
36 let node = match bridge::load_attestation(&repo, &self.id, &inputs)? {
37 bridge::Attestation::None => {
38 return Err(CliError::InvalidArgument {
39 message: format!(
40 "no attestation found for {}; run `atomic memory attest {}` first",
41 self.id, self.id
42 ),
43 })
44 }
45 bridge::Attestation::Stale(_) => {
46 return Err(CliError::InvalidArgument {
47 message: format!(
48 "the attestation for {} is stale (the memory changed since it was \
49 signed); re-run `atomic memory attest {}`",
50 self.id, self.id
51 ),
52 })
53 }
54 bridge::Attestation::Fresh(node) => *node,
55 };
56
57 // Resolve the public key. `did:atomic` is a key fingerprint (not
58 // recoverable to a key), so we verify against the default (or named)
59 // identity and let verify_memory's DID check catch a mismatch.
60 let store = IdentityStore::open_default().map_err(|e| {
61 CliError::Internal(anyhow::anyhow!("Failed to open identity store: {}", e))
62 })?;
63 let identity = if let Some(name) = &self.identity {
64 store
65 .load_by_name(name)
66 .map_err(|_| CliError::IdentityNotFound(name.clone()))?
67 } else {
68 store
69 .get_default()
70 .map_err(|e| {
71 CliError::Internal(anyhow::anyhow!("Failed to load default identity: {}", e))
72 })?
73 .ok_or_else(|| CliError::InvalidArgument {
74 message: "No default identity set. Create one first:\n \
75 atomic identity new <name> --email <email> --set-default"
76 .to_string(),
77 })?
78 };
79
80 verify_memory(&node, &identity.public_key).map_err(|e| CliError::InvalidArgument {
81 message: format!(
82 "verification failed: {e} (if this memory was attested by a different \
83 identity, pass --identity <name>)"
84 ),
85 })?;
86
87 println!("Verified memory: {}", self.id);
88 println!(

Callers

nothing calls this directly

Calls 7

find_repository_rootFunction · 0.85
read_memoryFunction · 0.85
load_by_nameMethod · 0.80
load_attestationFunction · 0.70
verify_memoryFunction · 0.50
cloneMethod · 0.45
get_defaultMethod · 0.45

Tested by

no test coverage detected