From 8fe018cfd89de75dff6c7672de2f8e5440343511 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 6 Sep 2021 10:19:29 +0200 Subject: [PATCH] move Kdf and KeyInfo to pbs_api_types workspace --- pbs-api-types/src/key_derivation.rs | 56 +++++++++++++++++++++++++++++ pbs-api-types/src/lib.rs | 3 ++ 2 files changed, 59 insertions(+) create mode 100644 pbs-api-types/src/key_derivation.rs diff --git a/pbs-api-types/src/key_derivation.rs b/pbs-api-types/src/key_derivation.rs new file mode 100644 index 00000000..9a53130c --- /dev/null +++ b/pbs-api-types/src/key_derivation.rs @@ -0,0 +1,56 @@ +use serde::{Deserialize, Serialize}; + +use proxmox::api::api; + +use crate::CERT_FINGERPRINT_SHA256_SCHEMA; + +#[api(default: "scrypt")] +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +/// Key derivation function for password protected encryption keys. +pub enum Kdf { + /// Do not encrypt the key. + None, + /// Encrypt they key with a password using SCrypt. + Scrypt, + /// Encrtypt the Key with a password using PBKDF2 + PBKDF2, +} + +impl Default for Kdf { + #[inline] + fn default() -> Self { + Kdf::Scrypt + } +} + +#[api( + properties: { + kdf: { + type: Kdf, + }, + fingerprint: { + schema: CERT_FINGERPRINT_SHA256_SCHEMA, + optional: true, + }, + }, +)] +#[derive(Deserialize, Serialize)] +/// Encryption Key Information +pub struct KeyInfo { + /// Path to key (if stored in a file) + #[serde(skip_serializing_if="Option::is_none")] + pub path: Option, + pub kdf: Kdf, + /// Key creation time + pub created: i64, + /// Key modification time + pub modified: i64, + /// Key fingerprint + #[serde(skip_serializing_if="Option::is_none")] + pub fingerprint: Option, + /// Password hint + #[serde(skip_serializing_if="Option::is_none")] + pub hint: Option, +} + diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 427b2d9f..7b978e82 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -34,6 +34,9 @@ macro_rules! SNAPSHOT_PATH_REGEX_STR { ); } +mod key_derivation; +pub use key_derivation::{Kdf, KeyInfo}; + #[macro_use] mod userid; pub use userid::Authid;