Skip to content

Commit

Permalink
Merge pull request #81 from Cosmian/fix/cloudproof_rust_integration
Browse files Browse the repository at this point in the history
Fix/cloudproof rust integration
  • Loading branch information
tbrezot authored Nov 20, 2023
2 parents c31547d + af9d095 commit cbaa37e
Show file tree
Hide file tree
Showing 28 changed files with 1,771 additions and 971 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ jobs:
bench:
uses: Cosmian/reusable_workflows/.github/workflows/cargo-bench.yml@develop
with:
toolchain: nightly-2022-10-28
toolchain: stable
force: true
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ jobs:
cargo-lint:
uses: Cosmian/reusable_workflows/.github/workflows/cargo-nursery.yml@develop
with:
toolchain: nightly-2022-10-28
toolchain: stable
cargo-publish:
needs:
- cargo-lint
uses: Cosmian/reusable_workflows/.github/workflows/cargo-publish.yml@develop
if: startsWith(github.ref, 'refs/tags/')
with:
toolchain: nightly-2022-10-28
toolchain: stable
secrets: inherit
cleanup:
needs:
Expand Down
10 changes: 2 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ repos:
hooks:
- id: shellcheck

- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: cargo-check

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down Expand Up @@ -119,8 +114,7 @@ repos:
- repo: https://github.com/Cosmian/git-hooks.git
rev: v1.0.16
hooks:
- id: dprint-toml-fix
- id: cargo-format
- id: stable-cargo-format
- id: cargo-upgrade
- id: cargo-update
- id: cargo-machete
Expand All @@ -133,6 +127,6 @@ repos:
- id: clippy-autofix-nursery
- id: clippy-autofix-others
- id: clippy-all-targets-all-features
- id: clippy-all-targets-all-features-release
- id: stable-cargo-format
- id: cargo-dry-publish
args: [--allow-dirty]
16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ path = "src/lib.rs"
in_memory = ["cosmian_crypto_core/ser"]

[dependencies]
cosmian_crypto_core = { version = "9.2.0", default-features = false, features = ["aes", "sha3"]}
# Once available in stable Rust (presumably 1.74), use std async fn in trait
# <https://rust-lang.github.io/rfcs/3185-static-async-fn-in-trait.html>
async-trait = "0.1.74"
base64 = "0.21.5"
cosmian_crypto_core = { version = "9.3.0", default-features = false, features = [
"aes",
"sha3",
] }
# Once available in stable Rust, use `!` std primitive
# <https://doc.rust-lang.org/std/primitive.never.html>
never = "0.1.0"
tiny-keccak = { version = "2.0.2", features = ["kmac", "sha3"] }
tracing = "0.1"
zeroize = "1.6.0"

[dev-dependencies]
cosmian_crypto_core = { version = "9.0.1", default-features = false, features = ["aes", "sha3", "ser"]}
actix-rt = "2.8.0"
actix-rt = "2.9.0"
criterion = "0.5.1"
futures = "0.3.28"
rand = "0.8.5"
Expand Down
30 changes: 13 additions & 17 deletions benches/benches.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use std::collections::{HashMap, HashSet};

use cosmian_crypto_core::CsRng;
use cosmian_findex::{
ChainTable, DxEnc, EntryTable, Findex, InMemoryEdx, Index, IndexedValue, Keyword, Label,
Location,
ChainTable, DxEnc, EntryTable, Findex, InMemoryEdx, Index, IndexedValue,
IndexedValueToKeywordsMap, Keyword, Keywords, Label, Location,
};
use criterion::{criterion_group, criterion_main, Criterion};
use futures::executor::block_on;
use rand::SeedableRng;

async fn user_interrupt(_res: HashMap<Keyword, HashSet<IndexedValue<Keyword, Location>>>) -> bool {
false
}

fn prepare_locations_and_words(
number: usize,
) -> HashMap<IndexedValue<Keyword, Location>, HashSet<Keyword>> {
fn prepare_locations_and_words(number: usize) -> IndexedValueToKeywordsMap {
let mut locations_and_words = HashMap::with_capacity(number);
for idx in 0..number {
let mut words = HashSet::new();
words.insert(Keyword::from(format!("first_name_{idx}").as_bytes()));
words.insert(Keyword::from(format!("name_{idx}").as_bytes()));
locations_and_words.insert(
IndexedValue::Data(Location::from(idx.to_be_bytes().as_slice())),
words.clone(),
Keywords::from(words.clone()),
);
}
locations_and_words
IndexedValueToKeywordsMap::from(locations_and_words)
}

fn prepare_keywords(number: usize) -> HashSet<Keyword> {
Expand All @@ -53,7 +44,7 @@ fn bench_search(c: &mut Criterion) {
//
// Prepare indexes to be search
//
let mut findex = Findex::new(
let findex = Findex::new(
EntryTable::setup(InMemoryEdx::default()),
ChainTable::setup(InMemoryEdx::default()),
);
Expand Down Expand Up @@ -83,8 +74,13 @@ fn bench_search(c: &mut Criterion) {
let keywords = prepare_keywords(n_keywords);
group.bench_function(format!("Searching {n_keywords} keyword(s)"), |b| {
b.iter(|| {
block_on(findex.search(&master_key, &label, keywords.clone(), &user_interrupt))
.expect("search failed");
block_on(findex.search(
&master_key,
&label,
Keywords::from(keywords.clone()),
&|_| async { Ok(false) },
))
.expect("search failed");
});
});
}
Expand Down
33 changes: 14 additions & 19 deletions examples/search.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use std::collections::{HashMap, HashSet};

use cosmian_findex::{
ChainTable, DxEnc, EntryTable, Findex, InMemoryEdx, Index, IndexedValue, Keyword, Label,
Location,
ChainTable, DxEnc, EntryTable, Findex, InMemoryEdx, Index, IndexedValue,
IndexedValueToKeywordsMap, Keyword, Keywords, Label, Location,
};
use futures::executor::block_on;

fn prepare_keywords(number: i64) -> HashSet<Keyword> {
fn prepare_keywords(number: i64) -> Keywords {
let mut keywords = HashSet::new();
for idx in 0..number {
keywords.insert(Keyword::from(format!("name_{idx}").as_str()));
}
keywords
Keywords::from(keywords)
}

fn prepare_locations_and_words(
number: i64,
) -> HashMap<IndexedValue<Keyword, Location>, HashSet<Keyword>> {
fn prepare_locations_and_words(number: i64) -> IndexedValueToKeywordsMap {
let mut locations_and_words = HashMap::new();
for idx in 0..number {
let mut words = HashSet::new();
Expand All @@ -28,14 +23,10 @@ fn prepare_locations_and_words(

locations_and_words.insert(
IndexedValue::Data(Location::from(idx.to_be_bytes().as_slice())),
words.clone(),
Keywords::from(words.clone()),
);
}
locations_and_words
}

async fn user_interrupt(_res: HashMap<Keyword, HashSet<IndexedValue<Keyword, Location>>>) -> bool {
false
IndexedValueToKeywordsMap::from(locations_and_words)
}

fn main() {
Expand All @@ -44,7 +35,7 @@ fn main() {
//
// Prepare indexes to be search
//
let mut findex = Findex::new(
let findex = Findex::new(
EntryTable::setup(InMemoryEdx::default()),
ChainTable::setup(InMemoryEdx::default()),
);
Expand All @@ -58,7 +49,11 @@ fn main() {
//
let keywords = prepare_keywords(1000);
for _ in 0..1000 {
block_on(findex.search(&master_key, &label, keywords.clone(), &user_interrupt))
.expect("search failed");
block_on(
findex.search(&master_key, &label, keywords.clone(), &|_| async {
Ok(false)
}),
)
.expect("search failed");
}
}
39 changes: 17 additions & 22 deletions examples/upsert.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use std::collections::{HashMap, HashSet};
use std::collections::HashMap;

use cosmian_findex::{
ChainTable, DxEnc, EntryTable, Findex, InMemoryEdx, Index, IndexedValue, Keyword, Label,
Location,
ChainTable, DxEnc, EntryTable, Findex, InMemoryEdx, Index, IndexedValue,
IndexedValueToKeywordsMap, Keyword, Keywords, Label, Location,
};
use futures::executor::block_on;

/// Converts the given strings as a `HashSet` of Keywords.
///
/// - `keywords` : strings to convert
fn hashset_keywords(keywords: &[&'static str]) -> HashSet<Keyword> {
keywords
.iter()
.map(|keyword| Keyword::from(*keyword))
.collect()
}

fn main() {
let mut indexed_value_to_keywords = HashMap::new();

// direct location robert doe
let robert_doe_location = Location::from("robert doe DB location");
indexed_value_to_keywords.insert(
IndexedValue::Data(robert_doe_location),
hashset_keywords(&["robert", "doe"]),
Keywords::from_iter(["robert", "doe"]),
);

// direct location john doe
let john_doe_location = Location::from("john doe DB location");
indexed_value_to_keywords.insert(
IndexedValue::Data(john_doe_location),
hashset_keywords(&["john", "doe"]),
Keywords::from_iter(["john", "doe"]),
);

// direct location for rob...
let rob_location = Location::from("rob DB location");
indexed_value_to_keywords.insert(IndexedValue::Data(rob_location), hashset_keywords(&["rob"]));
indexed_value_to_keywords.insert(
IndexedValue::Data(rob_location),
Keywords::from_iter(["rob"]),
);
// ... and indirection to robert
indexed_value_to_keywords.insert(
IndexedValue::Pointer(Keyword::from("robert")),
hashset_keywords(&["rob"]),
Keywords::from_iter(["rob"]),
);

let mut findex = Findex::new(
let findex = Findex::new(
EntryTable::setup(InMemoryEdx::default()),
ChainTable::setup(InMemoryEdx::default()),
);
Expand All @@ -54,6 +44,11 @@ fn main() {
let label = Label::from("label");

for _ in 0..1_000_000 {
block_on(findex.add(&master_key, &label, indexed_value_to_keywords.clone())).unwrap();
block_on(findex.add(
&master_key,
&label,
IndexedValueToKeywordsMap::from(indexed_value_to_keywords.clone()),
))
.unwrap();
}
}
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

Loading

0 comments on commit cbaa37e

Please sign in to comment.