gix_hash/
verify.rs

1use crate::{oid, ObjectId};
2
3/// The error returned by [`oid::verify()`].
4#[derive(Debug, thiserror::Error)]
5#[allow(missing_docs)]
6#[error("Hash was {actual}, but should have been {expected}")]
7pub struct Error {
8    pub actual: ObjectId,
9    pub expected: ObjectId,
10}
11
12impl oid {
13    /// Verify that `self` matches the `expected` object ID.
14    ///
15    /// Returns an [`Error`] containing both object IDs if they differ.
16    #[inline]
17    pub fn verify(&self, expected: &oid) -> Result<(), Error> {
18        if self == expected {
19            Ok(())
20        } else {
21            Err(Error {
22                actual: self.to_owned(),
23                expected: expected.to_owned(),
24            })
25        }
26    }
27}