@@ -18,7 +18,8 @@ use crate::{
1818 } ,
1919 Context ,
2020} ;
21- use commonware_codec:: Codec ;
21+ use bytes:: { Buf , BufMut } ;
22+ use commonware_codec:: { Codec , EncodeSize , Read , Write } ;
2223use commonware_cryptography:: { Digest , Hasher } ;
2324use commonware_parallel:: { Sequential , Strategy } ;
2425use futures:: stream:: Stream ;
@@ -30,6 +31,51 @@ pub struct KeyValueProof<F: merkle::Family, K: Key, D: Digest, const N: usize> {
3031 pub next_key : K ,
3132}
3233
34+ impl < F : merkle:: Family , K : Key , D : Digest , const N : usize > Write for KeyValueProof < F , K , D , N > {
35+ fn write ( & self , buf : & mut impl BufMut ) {
36+ self . proof . write ( buf) ;
37+ self . next_key . write ( buf) ;
38+ }
39+ }
40+
41+ impl < F : merkle:: Family , K : Key , D : Digest , const N : usize > EncodeSize
42+ for KeyValueProof < F , K , D , N >
43+ {
44+ fn encode_size ( & self ) -> usize {
45+ self . proof . encode_size ( ) + self . next_key . encode_size ( )
46+ }
47+ }
48+
49+ impl < F : merkle:: Family , K : Key , D : Digest , const N : usize > Read for KeyValueProof < F , K , D , N > {
50+ /// `(max_digests, key_cfg)`: the total digest cap for the embedded operation proof and the
51+ /// read configuration for the key type.
52+ type Cfg = ( usize , <K as Read >:: Cfg ) ;
53+
54+ fn read_cfg (
55+ buf : & mut impl Buf ,
56+ ( max_digests, key_cfg) : & Self :: Cfg ,
57+ ) -> Result < Self , commonware_codec:: Error > {
58+ let proof = OperationProof :: < F , D , N > :: read_cfg ( buf, max_digests) ?;
59+ let next_key = K :: read_cfg ( buf, key_cfg) ?;
60+ Ok ( Self { proof, next_key } )
61+ }
62+ }
63+
64+ #[ cfg( feature = "arbitrary" ) ]
65+ impl < F : merkle:: Family , K : Key , D : Digest , const N : usize > arbitrary:: Arbitrary < ' _ >
66+ for KeyValueProof < F , K , D , N >
67+ where
68+ K : for < ' a > arbitrary:: Arbitrary < ' a > ,
69+ D : for < ' a > arbitrary:: Arbitrary < ' a > ,
70+ {
71+ fn arbitrary ( u : & mut arbitrary:: Unstructured < ' _ > ) -> arbitrary:: Result < Self > {
72+ Ok ( Self {
73+ proof : u. arbitrary ( ) ?,
74+ next_key : u. arbitrary ( ) ?,
75+ } )
76+ }
77+ }
78+
3379/// The generic Db type for ordered Current QMDB variants.
3480///
3581/// This type is generic over the index type `I`, allowing it to be used with both regular
0 commit comments