Skip to content

Commit 2585069

Browse files
author
Bennett Hardwick
committed
Comments, bump version
1 parent ebf21a6 commit 2585069

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ homepage = "https://cipherstash.com"
55
repository = "https://github.com/cipherstash/cipherstash-dynamodb"
66
readme = "README.md"
77
description = "CipherStash client for storing and querying encrypted data in DynamoDB"
8-
version = "0.6.0"
8+
version = "0.7.0"
99
edition = "2021"
1010

1111
[package.metadata.docs.rs]
@@ -25,7 +25,7 @@ repository = "https://github.com/cipherstash/cipherstash-dynamodb"
2525

2626
[dependencies]
2727
cipherstash-client = { version = "0.10", registry = "cipherstash" }
28-
cipherstash-dynamodb-derive = { version = "0.6", path = "cipherstash-dynamodb-derive", registry = "cipherstash" }
28+
cipherstash-dynamodb-derive = { version = "0.7", path = "cipherstash-dynamodb-derive", registry = "cipherstash" }
2929

3030
aws-sdk-dynamodb = "1.3.0"
3131
async-trait = "0.1.73"

cipherstash-dynamodb-derive/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cipherstash-dynamodb-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ license-file = "../LICENSE.md"
44
homepage = "https://cipherstash.com"
55
readme = "../README.md"
66
description = "Derive macros for the CipherStash client for DynamoDB"
7-
version = "0.6.0"
7+
version = "0.7.0"
88
edition = "2021"
99

1010
[lib]

src/crypto/mod.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ pub use sealed::{SealedTableEntry, UnsealSpec};
2323
pub use sealer::Sealer;
2424
pub use unsealed::Unsealed;
2525

26+
/// In order to stop indexes from exploding with indexes on large strings, cap the number of terms
27+
/// generated per index. Since there is a fixed number of terms per index it is also possible to
28+
/// delete all index terms for a particular record.
2629
const MAX_TERMS_PER_INDEX: usize = 25;
2730

2831
#[derive(Debug, Error)]
@@ -65,6 +68,9 @@ pub fn format_term_key(
6568
format!("{sort_key}#{index_name}#{index_type}#{counter}")
6669
}
6770

71+
/// Get all the term index keys for a particular sort key and index definitions
72+
///
73+
/// This is used to delete any index items that shouldn't exist during either an update or
6874
pub(crate) fn all_index_keys<'a>(
6975
sort_key: &str,
7076
protected_indexes: impl AsRef<[(Cow<'a, str>, IndexType)]>,
@@ -81,14 +87,14 @@ pub(crate) fn all_index_keys<'a>(
8187
.collect()
8288
}
8389

84-
pub fn hmac<C>(
90+
/// Use a CipherStash [`ExactIndex`] to take the HMAC of a string with a provided salt
91+
///
92+
/// This value is used for term index keys and "encrypted" partition / sort keys
93+
pub fn hmac(
8594
value: &str,
8695
salt: Option<&str>,
87-
cipher: &Encryption<C>,
88-
) -> Result<Vec<u8>, EncryptionError>
89-
where
90-
C: Credentials<Token = ServiceToken>,
91-
{
96+
cipher: &Encryption<impl Credentials<Token = ServiceToken>>,
97+
) -> Result<Vec<u8>, EncryptionError> {
9298
let plaintext = Plaintext::Utf8Str(Some(value.to_string()));
9399
let index = CompoundIndex::new(ExactIndex::new(vec![]));
94100

src/encrypted_table/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ impl<D> EncryptedTable<D> {
366366
let sealed = sealer.seal(protected_attributes, &self.cipher, 12).await?;
367367

368368
let mut put_records = Vec::with_capacity(sealed.len());
369+
370+
// When doing an upsert you need to delete any index keys that are not used for the current
371+
// record but may have been used for previous records.
369372
let mut delete_records = vec![];
370373

371374
let PrimaryKeyParts { pk, sk } = sealed.primary_key();
@@ -383,6 +386,7 @@ impl<D> EncryptedTable<D> {
383386
for index_sk in all_index_keys(&sk, protected_indexes) {
384387
let index_sk = b64_encode(hmac(&index_sk, Some(pk.as_str()), &self.cipher)?);
385388

389+
// If the current put has an index with the specified key then don't delete it.
386390
if seen_sk.contains(&index_sk) {
387391
continue;
388392
}
@@ -399,6 +403,8 @@ impl<D> EncryptedTable<D> {
399403
})
400404
}
401405

406+
/// Take a prepared primary key and encrypt it to get the [`PrimaryKeyParts`] which can be used
407+
/// for retrieval.
402408
pub fn encrypt_primary_key_parts(
403409
&self,
404410
prepared_primary_key: PreparedPrimaryKey,

0 commit comments

Comments
 (0)