Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.envrc
.env
.DS_Store
.mise.toml
3 changes: 2 additions & 1 deletion src/crypto/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ impl SealedTableEntry {
}

let decrypted = async_map_somes(decryptable_items, |items| cipher.decrypt(items)).await?;
let mut chunks_exact = decrypted.chunks_exact(protected_attributes.len());
let mut default_iter =
std::iter::repeat_with::<&[Option<Plaintext>], _>(|| &[]).take(plaintext_items.len());

let mut chunks_exact;
let decrypted_iter: &mut dyn Iterator<Item = &[Option<Plaintext>]> =
if protected_attributes.len() > 0 {
chunks_exact = decrypted.chunks_exact(protected_attributes.len());
&mut chunks_exact
} else {
&mut default_iter
Expand Down
59 changes: 59 additions & 0 deletions tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ impl User {
}
}

#[derive(
Identifiable, Encryptable, Decryptable, Searchable, Debug, PartialEq, Ord, PartialOrd, Eq,
)]
#[cipherstash(sort_key_prefix = "user")]
pub struct PublicUser {
#[partition_key]
#[cipherstash(skip)]
pub email: String,

#[cipherstash(skip)]
pub name: String,

#[cipherstash(skip)]
pub tag: String,

#[cipherstash(skip)]
pub temp: bool,
}

impl PublicUser {
pub fn new(email: impl Into<String>, name: impl Into<String>, tag: impl Into<String>) -> Self {
Self {
name: name.into(),
email: email.into(),
tag: tag.into(),
temp: false,
}
}
}

async fn run_test<F: Future<Output = ()>>(mut f: impl FnMut(EncryptedTable) -> F) {
let config = aws_config::from_env()
.endpoint_url("http://localhost:8000")
Expand Down Expand Up @@ -193,3 +223,32 @@ async fn test_delete() {
})
.await;
}

#[tokio::test]
#[serial]
async fn test_insert_retrieve_public() {
let config = aws_config::from_env()
.endpoint_url("http://localhost:8000")
.load()
.await;

let client = aws_sdk_dynamodb::Client::new(&config);

let table_name = "test-public-users-pk";

common::create_table(&client, table_name).await;

let table = EncryptedTable::init(client, table_name)
.await
.expect("Failed to init table");

table
.put(PublicUser::new("[email protected]", "Dan Draper", "blue"))
.await
.expect("Failed to insert Dan");

table
.get::<PublicUser>("[email protected]")
.await
.expect("Failed to get Dan");
}
Loading