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

Function verify_binding_content

atomic-repository/src/git_binding/verify.rs:35–130  ·  view source on GitHub ↗

Verify the binding against the live Git object database (RFC §5.2 structural check): the commit exists, its tree matches `git_tree`, its complete ordered parents match `git_parents`, and preserved raw commit bytes (when present) are byte-identical to the stored object. This never trusts the signature and never materializes anything.

(
    git: &git2::Repository,
    binding: &GitStateBinding,
)

Source from the content-addressed store, hash-verified

33///
34/// This never trusts the signature and never materializes anything.
35pub fn verify_binding_content(
36 git: &git2::Repository,
37 binding: &GitStateBinding,
38) -> Result<(), BindingVerificationError> {
39 let payload = binding.payload();
40 payload
41 .validate()
42 .map_err(BindingVerificationError::Invalid)?;
43
44 // Object-format consistency: every OID must carry the format's width.
45 let algorithm = match payload.git_object_format {
46 GitObjectFormat::Sha1 => GitHashAlgorithm::Sha1,
47 GitObjectFormat::Sha256 => GitHashAlgorithm::Sha256,
48 };
49 for oid in std::iter::once(&payload.git_commit)
50 .chain(std::iter::once(&payload.git_tree))
51 .chain(payload.git_parents.iter())
52 {
53 let object_id = oid.to_git_object_id()?;
54 if object_id.algorithm() != algorithm {
55 return Err(BindingVerificationError::FormatMismatch {
56 expected: format!("{algorithm:?}"),
57 oid: oid.to_hex(),
58 });
59 }
60 }
61
62 let commit_oid = git2_oid(&payload.git_commit)?;
63 let commit = git
64 .find_commit(commit_oid)
65 .map_err(|error| BindingVerificationError::Git {
66 message: format!(
67 "bound commit {} is absent: {error}",
68 payload.git_commit.to_hex()
69 ),
70 })?;
71 let odb = git.odb().map_err(|error| BindingVerificationError::Git {
72 message: error.to_string(),
73 })?;
74 let raw = odb
75 .read(commit_oid)
76 .map_err(|error| BindingVerificationError::Git {
77 message: format!(
78 "bound commit {} is unreadable: {error}",
79 payload.git_commit.to_hex()
80 ),
81 })?
82 .data()
83 .to_vec();
84
85 // Tree: the binding must name the commit's actual tree.
86 let actual_tree = commit.tree_id();
87 if actual_tree.as_bytes() != payload.git_tree.as_bytes() {
88 return Err(BindingVerificationError::TreeMismatch {
89 expected: payload.git_tree.to_hex(),
90 found: actual_tree.to_string(),
91 });
92 }

Calls 14

commit_object_digestFunction · 0.85
to_git_object_idMethod · 0.80
git2_oidFunction · 0.70
payloadMethod · 0.45
validateMethod · 0.45
iterMethod · 0.45
algorithmMethod · 0.45
to_hexMethod · 0.45
dataMethod · 0.45
readMethod · 0.45
as_bytesMethod · 0.45
lenMethod · 0.45