Skip to content

Commit 8c692f8

Browse files
authored
Merge pull request #67 from cipherstash/fix-chunk-bug
Fix bug in unseal_all where it will panic if there is no protected_at…
2 parents 23df0c1 + 2dceb5d commit 8c692f8

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/crypto/sealed.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ impl SealedTableEntry {
109109
}
110110

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

115+
let mut chunks_exact;
116116
let decrypted_iter: &mut dyn Iterator<Item = &[Option<Plaintext>]> =
117117
if protected_attributes.len() > 0 {
118+
chunks_exact = decrypted.chunks_exact(protected_attributes.len());
118119
&mut chunks_exact
119120
} else {
120121
&mut default_iter

tests/query_tests.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,36 @@ impl User {
3737
}
3838
}
3939

40+
#[derive(
41+
Identifiable, Encryptable, Decryptable, Searchable, Debug, PartialEq, Ord, PartialOrd, Eq,
42+
)]
43+
#[cipherstash(sort_key_prefix = "user")]
44+
pub struct PublicUser {
45+
#[partition_key]
46+
#[cipherstash(skip)]
47+
pub email: String,
48+
49+
#[cipherstash(skip)]
50+
pub name: String,
51+
52+
#[cipherstash(skip)]
53+
pub tag: String,
54+
55+
#[cipherstash(skip)]
56+
pub temp: bool,
57+
}
58+
59+
impl PublicUser {
60+
pub fn new(email: impl Into<String>, name: impl Into<String>, tag: impl Into<String>) -> Self {
61+
Self {
62+
name: name.into(),
63+
email: email.into(),
64+
tag: tag.into(),
65+
temp: false,
66+
}
67+
}
68+
}
69+
4070
async fn run_test<F: Future<Output = ()>>(mut f: impl FnMut(EncryptedTable) -> F) {
4171
let config = aws_config::from_env()
4272
.endpoint_url("http://localhost:8000")
@@ -193,3 +223,32 @@ async fn test_delete() {
193223
})
194224
.await;
195225
}
226+
227+
#[tokio::test]
228+
#[serial]
229+
async fn test_insert_retrieve_public() {
230+
let config = aws_config::from_env()
231+
.endpoint_url("http://localhost:8000")
232+
.load()
233+
.await;
234+
235+
let client = aws_sdk_dynamodb::Client::new(&config);
236+
237+
let table_name = "test-public-users-pk";
238+
239+
common::create_table(&client, table_name).await;
240+
241+
let table = EncryptedTable::init(client, table_name)
242+
.await
243+
.expect("Failed to init table");
244+
245+
table
246+
.put(PublicUser::new("dan@coderdan.co", "Dan Draper", "blue"))
247+
.await
248+
.expect("Failed to insert Dan");
249+
250+
table
251+
.get::<PublicUser>("dan@coderdan.co")
252+
.await
253+
.expect("Failed to get Dan");
254+
}

0 commit comments

Comments
 (0)