Skip to content

Commit

Permalink
fix: use fixed-length tags in CS-RH-DX-Enc
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrezot committed Feb 8, 2024
1 parent bfa7346 commit 40fdcf3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
17 changes: 7 additions & 10 deletions src/dx_enc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ pub trait DynRhDxEnc<
}

#[async_trait(?Send)]
pub trait CsRhDxEnc<
const VALUE_LENGTH: usize,
Tag: Hash + Eq + PartialEq,
DbConnection: DbInterface,
>: DynRhDxEnc<VALUE_LENGTH, Tag, DbConnection>
pub trait CsRhDxEnc<const TAG_LENGTH: usize, const VALUE_LENGTH: usize, DbConnection: DbInterface>:
DynRhDxEnc<VALUE_LENGTH, [u8; TAG_LENGTH], DbConnection>
{
/// Merges the given DX to the stored one. Use the existing bindings in case
/// of conflict.
Expand All @@ -50,8 +47,8 @@ pub trait CsRhDxEnc<
/// alongside its EDX form.
async fn insert(
&self,
dx: Dx<Tag, VALUE_LENGTH>,
) -> Result<(Dx<Tag, VALUE_LENGTH>, Edx), Self::Error>;
dx: Dx<[u8; TAG_LENGTH], VALUE_LENGTH>,
) -> Result<(Dx<[u8; TAG_LENGTH], VALUE_LENGTH>, Edx), Self::Error>;

/// Merges the given new DX to the stored one conditionally to the fact that
/// for each tag, the ciphertext bound to this tag in the stored EDX is
Expand All @@ -65,12 +62,12 @@ pub trait CsRhDxEnc<
async fn upsert(
&self,
old_dx: Edx,
new_dx: Dx<Tag, VALUE_LENGTH>,
) -> Result<(Dx<Tag, VALUE_LENGTH>, Edx), Self::Error>;
new_dx: Dx<[u8; TAG_LENGTH], VALUE_LENGTH>,
) -> Result<(Dx<[u8; TAG_LENGTH], VALUE_LENGTH>, Edx), Self::Error>;

/// Rebuilds the entire EDX using the given key.
async fn rebuild(self, seed: &[u8]) -> Result<Self, Self::Error>;

/// Returns the stored DX.
async fn dump(&self) -> Result<Dx<Tag, VALUE_LENGTH>, Self::Error>;
async fn dump(&self) -> Result<Dx<[u8; TAG_LENGTH], VALUE_LENGTH>, Self::Error>;
}
2 changes: 1 addition & 1 deletion src/dx_enc/vera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<const VALUE_LENGTH: usize, DbConnection: DbInterface>

#[async_trait(?Send)]
impl<const VALUE_LENGTH: usize, DbConnection: DbInterface>
CsRhDxEnc<VALUE_LENGTH, Tag, DbConnection> for Vera<DbConnection>
CsRhDxEnc<TAG_LENGTH, VALUE_LENGTH, DbConnection> for Vera<DbConnection>
{
async fn insert(
&self,
Expand Down
17 changes: 10 additions & 7 deletions src/mm_enc/findex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ use cosmian_crypto_core::reexport::rand_core::CryptoRngCore;
use tiny_keccak::{Hasher, Sha3};

use crate::{
edx::{CsRhDxEnc, Token},
dx_enc::{CsRhDxEnc, Token},
error::Error,
findex_mm::{
structs::{Entry, Link, Operation},
FindexMultiMap, MmEnc, ENTRY_LENGTH, LINK_LENGTH,
mm_enc::{
// structs::{Entry, Link, Operation},
FindexMultiMap,
MmEnc,
ENTRY_LENGTH,
LINK_LENGTH,
},
parameters::{BLOCK_LENGTH, HASH_LENGTH, LINE_WIDTH, SEED_LENGTH},
CoreError, DbInterfaceErrorTrait, Label,
parameters::{BLOCK_LENGTH, HASH_LENGTH, LINE_WIDTH},
CoreError, DbInterfaceErrorTrait,
};

impl<
UserError: DbInterfaceErrorTrait,
EntryTable: CsRhDxEnc<ENTRY_LENGTH, Error = Error<UserError>>,
ChainTable: CsRhDxEnc<LINK_LENGTH, Error = Error<UserError>>,
ChainTable: DynRhDxEnc<LINK_LENGTH, Error = Error<UserError>>,
> FindexMultiMap<UserError, EntryTable, ChainTable>
{
/// Instantiates a new `FindexMultiMap`.
Expand Down

0 comments on commit 40fdcf3

Please sign in to comment.