Permalink
Browse files

Check that the values stored in content-addressable stores are correct

Fix #189
  • Loading branch information...
samoht committed Dec 26, 2018
1 parent 3cd4ec5 commit df8fc25eafbd2a29ab915a67ecf0619c3ea519a2
Showing with 15 additions and 2 deletions.
  1. +15 −2 src/irmin/irmin.ml
@@ -58,9 +58,22 @@ module Content_addressable (AO: APPEND_ONLY_STORE_MAKER)
struct
include AO(K)(V)

let pp_key = Type.pp K.t

let digest v = K.digest (Type.encode_bin V.t v)

let find t k =
find t k >>= function
| None -> Lwt.return None
| Some v as r ->
let k' = digest v in
if Type.equal K.t k k' then Lwt.return r
else
Fmt.kstrf Lwt.fail_invalid_arg
"corrupted value: got %a, expecting %a" pp_key k' pp_key k

let add t v =
let s = Type.encode_bin V.t v in
let k = K.digest s in
let k = digest v in
add t k v >|= fun () ->
k

0 comments on commit df8fc25

Please sign in to comment.