File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ pub use object_id::{decode, ObjectId};
24
24
///
25
25
pub mod prefix;
26
26
27
+ ///
28
+ pub mod verify;
29
+
27
30
/// A partial, owned hash possibly identifying an object uniquely, whose non-prefix bytes are zeroed.
28
31
///
29
32
/// An example would `0000000000000000000000000000000032bd3242`, where `32bd3242` is the prefix,
Original file line number Diff line number Diff line change
1
+ use 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}" ) ]
7
+ pub struct Error {
8
+ actual : ObjectId ,
9
+ expected : ObjectId ,
10
+ }
11
+
12
+ impl 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
+ }
You can’t perform that action at this time.
0 commit comments