I found that I wanted to compare two lists of cstructs if they each combined contained the same bytes. It can easily but inefficiently be implemented using Cstruct.equal (Cstruct.concat xs) (Cstruct.concat ys). Implementing it more efficiently is less straight forward.
let cstruct_equalv a b =
let rec loop a b =
match a, b with
| [], [] -> true
| [], _ | _, [] -> false
| a :: a', b :: b' ->
let l = min (Cstruct.length a) (Cstruct.length b) in
let remainder x xs =
if Cstruct.length x > l then
Cstruct.sub x l (Cstruct.length x - l) :: xs
else
xs
in
Cstruct.equal (Cstruct.sub a 0 l) (Cstruct.sub b 0 l) &&
loop (remainder a a') (remainder b b')
in
Cstruct.lenv a = Cstruct.lenv b &&
loop a b
It may be a slippery slope to add more and more *v functions.
I found that I wanted to compare two lists of cstructs if they each combined contained the same bytes. It can easily but inefficiently be implemented using
Cstruct.equal (Cstruct.concat xs) (Cstruct.concat ys). Implementing it more efficiently is less straight forward.It may be a slippery slope to add more and more *v functions.