feat: use phf::Set for supported versions

This commit is contained in:
2021-04-13 20:00:56 +02:00
parent f7c699f1f0
commit 548e934770
6 changed files with 77 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ uuid = "0.8"
crdts = "6.2"
gpgme = "0.9"
dyn-clone = "1"
phf = {version = "0.8", features = ["macros"]}
[dependencies.crdt-enc]
path = "../crdt-enc"

View File

@@ -3,7 +3,8 @@ use ::async_trait::async_trait;
use ::crdt_enc::{
key_cryptor::Keys,
utils::{
decode_version_bytes_mvreg_custom, encode_version_bytes_mvreg_custom, LockBox, VersionBytes,
decode_version_bytes_mvreg_custom_phf, encode_version_bytes_mvreg_custom, LockBox,
VersionBytes,
},
CoreSubHandle, Info,
};
@@ -14,10 +15,10 @@ use ::uuid::Uuid;
const CURRENT_VERSION: Uuid = Uuid::from_u128(0xe69cb68e_7fbb_41aa_8d22_87eace7a04c9);
// needs to be sorted!
const SUPPORTED_VERSIONS: &[Uuid] = &[
Uuid::from_u128(0xe69cb68e_7fbb_41aa_8d22_87eace7a04c9), // current
];
static SUPPORTED_VERSIONS: phf::Set<u128> = phf::phf_set! {
// current
0x_e69cb68e_7fbb_41aa_8d22_87eace7a04c9_u128,
};
pub fn init() {
gpgme::init();
@@ -88,12 +89,15 @@ impl crdt_enc::key_cryptor::KeyCryptor for KeyHandler {
Ok((data.remote_meta.clone(), core))
})?;
let keys_ctx =
decode_version_bytes_mvreg_custom(&remote_meta, SUPPORTED_VERSIONS, |buf| async move {
let keys_ctx = decode_version_bytes_mvreg_custom_phf(
&remote_meta,
&SUPPORTED_VERSIONS,
|buf| async move {
// TODO: decrypt key
Ok(buf)
})
.await?;
},
)
.await?;
core.set_keys(keys_ctx).await?;