Skip to content

v0.8.0

Compare
Choose a tag to compare
@coderdan coderdan released this 08 Oct 05:58
· 50 commits to main since this release
v0.8.0
fd4a248

What's Changed

Derive macros

Adds support for custom field functions so that arbitrary types can be added to Unsealed and encrypted.

For example, to handle a field with a BTreeMap:

#[derive(Debug, Clone, PartialEq, Searchable, Encryptable, Decryptable, Identifiable)]
struct Test {
    #[partition_key]
    pub pk: String,
    #[sort_key]
    pub sk: String,
    pub name: String,
    pub age: i16,
    #[cipherstash(plaintext)]
    pub tag: String,
    #[cipherstash(encryptable_with = put_attrs, decryptable_with = get_attrs)]
    pub attrs: BTreeMap<String, String>,
}

fn put_attrs(unsealed: &mut Unsealed, attrs: BTreeMap<String, String>) {
    attrs.into_iter().for_each(|(k, v)| {
        unsealed.add_protected_map_field("attrs", k, Plaintext::from(v));
    })
}

fn get_attrs<T>(unsealed: &mut Unsealed) -> Result<T, SealError>
where
    T: FromIterator<(String, String)>,
{
    unsealed
        .take_protected_map("attrs")
        .ok_or(TypeParseError("attrs".to_string()))?
        .into_iter()
        .map(|(k, v)| {
            TryFromPlaintext::try_from_plaintext(v)
                .map(|v| (k, v))
                .map_err(SealError::from)
        })
        .collect()
}

Full Changelog: v0.7.4...v0.8.0