Find an attestation by hash or hash prefix.
(&self, repo: &Repository, prefix: &str)
| 576 | |
| 577 | /// Find an attestation by hash or hash prefix. |
| 578 | fn find_by_prefix(&self, repo: &Repository, prefix: &str) -> CliResult<(Hash, Attestation)> { |
| 579 | // Try exact match first |
| 580 | if let Some(hash) = Hash::from_base32(prefix.as_bytes()) { |
| 581 | if let Ok(attest) = repo.load_attestation(&hash) { |
| 582 | return Ok((hash, attest)); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | // Prefix search |
| 587 | let prefix_lower = prefix.to_uppercase(); |
| 588 | let mut matches: Vec<(Hash, Attestation)> = Vec::new(); |
| 589 | |
| 590 | for result in repo.change_store().iter_attestations() { |
| 591 | let hash = match result { |
| 592 | Ok(h) => h, |
| 593 | Err(_) => continue, |
| 594 | }; |
| 595 | |
| 596 | let hash_str = hash.to_base32(); |
| 597 | if hash_str.starts_with(&prefix_lower) { |
| 598 | if let Ok(attest) = repo.load_attestation(&hash) { |
| 599 | matches.push((hash, attest)); |
| 600 | } |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | match matches.len() { |
| 605 | 0 => Err(CliError::InvalidArgument { |
| 606 | message: format!("No attestation found matching '{}'", prefix), |
| 607 | }), |
| 608 | 1 => Ok(matches.into_iter().next().unwrap()), |
| 609 | n => Err(CliError::InvalidArgument { |
| 610 | message: format!( |
| 611 | "Ambiguous hash prefix '{}' matches {} attestations. Be more specific.", |
| 612 | prefix, n, |
| 613 | ), |
| 614 | }), |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | /// Print a one-line summary of an attestation. |
| 619 | fn print_summary(&self, hash: &Hash, attest: &Attestation) { |
no test coverage detected