use super::responses::{
BackupKeyResponse, DecryptDataResponse, EncryptDataResponse, ExportKeyResponse,
GenerateDataKeyResponse, GenerateHmacResponse, GenerateRandomBytesResponse,
GetWrappingKeyResponse, HashDataResponse, ListKeysResponse, ReadKeyResponse,
ReadTransitCacheConfigurationResponse, RewrapDataResponse, SignDataResponse,
VerifySignedDataResponse,
};
use super::{
HashAlgorithm, HashFunction, KeyType, MarshalingAlgorithm, OutputFormat, SignatureAlgorithm,
};
use rustify_derive::Endpoint;
use serde::Serialize;
use std::fmt::Debug;
#[derive(Builder, Debug, Default, Endpoint, Serialize)]
#[endpoint(
path = "{self.mount}/keys/{self.name}",
method = "POST",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct CreateKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub convergent_encryption: Option<bool>,
pub derived: Option<bool>,
pub exportable: Option<bool>,
pub allow_plaintext_backup: Option<bool>,
#[serde(rename = "type")]
pub key_type: Option<KeyType>,
pub auto_rotate_period: Option<String>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/keys/{self.name}",
response = "ReadKeyResponse",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct ReadKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/keys",
response = "ListKeysResponse",
method = "LIST",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct ListKeysRequest {
#[endpoint(skip)]
pub mount: String,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/keys/{self.name}/config",
method = "POST",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct UpdateKeyConfigurationRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub min_decryption_version: Option<u64>,
pub min_encryption_version: Option<u64>,
pub deletion_allowed: Option<bool>,
pub exportable: Option<bool>,
pub allow_plaintext_backup: Option<bool>,
pub auto_rotate_period: Option<String>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/keys/{self.name}",
method = "DELETE",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct DeleteKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/keys/{self.name}/rotate",
method = "POST",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct RotateKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
}
#[derive(Builder, Debug, Default, Endpoint, Serialize)]
#[endpoint(
path = "{self.mount}/keys/{self.name}/import",
method = "POST",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct ImportKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub ciphertext: Option<String>,
pub hash_function: Option<HashFunction>,
#[serde(rename = "type")]
pub key_type: KeyType,
pub public_key: Option<String>,
pub allow_rotation: Option<bool>,
pub derived: Option<bool>,
pub context: Option<String>,
pub exportable: Option<bool>,
pub allow_plaintext_backup: Option<bool>,
pub auto_rotate_period: Option<String>,
}
#[derive(Builder, Debug, Default, Endpoint, Serialize)]
#[endpoint(
path = "{self.mount}/keys/{self.name}/import_version",
method = "POST",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct ImportKeyVersionRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub ciphertext: Option<String>,
pub hash_function: Option<HashFunction>,
pub public_key: Option<String>,
pub version: Option<u64>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/export/{self.key_type}/{self.name}{self.version}",
response = "ExportKeyResponse",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct ExportKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub key_type: ExportKeyType,
#[endpoint(skip)]
pub name: String,
#[endpoint(skip)]
pub version: ExportVersion,
}
#[derive(Clone, Copy, Debug)]
pub enum ExportKeyType {
EncryptionKey,
SigningKey,
HmacKey,
PublicKey,
CertificateChain,
CmacKey,
}
#[allow(clippy::derivable_impls)]
impl Default for ExportKeyType {
fn default() -> Self {
ExportKeyType::EncryptionKey
}
}
impl std::fmt::Display for ExportKeyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::EncryptionKey => write!(f, "encryption-key"),
Self::SigningKey => write!(f, "signing-key"),
Self::HmacKey => write!(f, "hmac-key"),
Self::PublicKey => write!(f, "public-key"),
Self::CertificateChain => write!(f, "certificate-chain"),
Self::CmacKey => write!(f, "cmac-key"),
}
}
}
#[derive(Clone, Copy, Debug)]
pub enum ExportVersion {
All,
Latest,
Version(u64),
}
#[allow(clippy::derivable_impls)]
impl Default for ExportVersion {
fn default() -> Self {
ExportVersion::Latest
}
}
impl std::fmt::Display for ExportVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::All => Ok(()),
Self::Latest => write!(f, "/latest"),
Self::Version(n) => write!(f, "/{n}"),
}
}
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/encrypt/{self.name}",
method = "POST",
response = "EncryptDataResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct EncryptDataRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub plaintext: String,
pub associated_data: Option<String>,
pub context: Option<String>,
pub key_version: Option<u64>,
pub nonce: Option<String>,
pub key_type: Option<KeyType>,
pub convergent_encryption: Option<String>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/decrypt/{self.name}",
method = "POST",
response = "DecryptDataResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct DecryptDataRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub ciphertext: String,
pub associated_data: Option<String>,
pub context: Option<String>,
pub nonce: Option<String>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/rewrap/{self.name}",
method = "POST",
response = "RewrapDataResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct RewrapDataRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub ciphertext: String,
pub context: Option<String>,
pub key_version: Option<u64>,
pub nonce: Option<String>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/datakey/{self.key_type}/{self.name}",
method = "POST",
response = "GenerateDataKeyResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct GenerateDataKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub key_type: DataKeyType,
#[endpoint(skip)]
pub name: String,
pub context: Option<String>,
pub nonce: Option<String>,
pub bits: Option<u16>,
}
#[derive(Clone, Copy, Debug)]
pub enum DataKeyType {
Plaintext,
Wrapped,
}
#[allow(clippy::derivable_impls)]
impl Default for DataKeyType {
fn default() -> Self {
DataKeyType::Wrapped
}
}
impl std::fmt::Display for DataKeyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Plaintext => write!(f, "plaintext"),
Self::Wrapped => write!(f, "wrapped"),
}
}
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/random",
method = "POST",
response = "GenerateRandomBytesResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct GenerateRandomBytesRequest {
#[endpoint(skip)]
pub mount: String,
pub bytes: Option<u32>,
pub format: OutputFormat,
pub source: RandomBytesSource,
}
#[derive(Clone, Copy, Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum RandomBytesSource {
Platform,
Seal,
All,
}
#[allow(clippy::derivable_impls)]
impl Default for RandomBytesSource {
fn default() -> Self {
RandomBytesSource::Platform
}
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/hash",
method = "POST",
response = "HashDataResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct HashDataRequest {
#[endpoint(skip)]
pub mount: String,
pub algorithm: Option<HashAlgorithm>,
pub input: String,
pub format: Option<OutputFormat>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/hmac/{self.name}",
method = "POST",
response = "GenerateHmacResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct GenerateHmacRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub key_version: Option<u64>,
pub algorithm: Option<HashAlgorithm>,
pub input: String,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/sign/{self.name}",
method = "POST",
response = "SignDataResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct SignDataRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub key_version: Option<u64>,
pub hash_algorithm: Option<HashAlgorithm>,
pub input: String,
pub context: Option<String>,
pub prehashed: Option<bool>,
pub signature_algorithm: Option<SignatureAlgorithm>,
pub marshaling_algorithm: Option<MarshalingAlgorithm>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/verify/{self.name}",
method = "POST",
response = "VerifySignedDataResponse",
builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct VerifySignedDataRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub hash_algorithm: Option<HashAlgorithm>,
pub input: String,
pub signature: Option<String>,
pub hmac: Option<String>,
pub context: Option<String>,
pub prehashed: Option<bool>,
pub signature_algorithm: Option<SignatureAlgorithm>,
pub marshaling_algorithm: Option<MarshalingAlgorithm>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/backup/{self.name}",
response = "BackupKeyResponse",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct BackupKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(path = "{self.mount}/restore", method = "POST", builder = "true")]
#[builder(setter(into, strip_option), default)]
pub struct RestoreKeyRequest {
#[endpoint(skip)]
pub mount: String,
pub backup: String,
pub name: Option<String>,
pub force: Option<bool>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/keys/{self.name}/trim",
method = "POST",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct TrimKeyRequest {
#[endpoint(skip)]
pub mount: String,
#[endpoint(skip)]
pub name: String,
pub min_available_version: u64,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(path = "{self.mount}/cache-config", method = "POST", builder = "true")]
#[builder(setter(into, strip_option), default)]
pub struct ConfigureCacheRequest {
#[endpoint(skip)]
pub mount: String,
pub size: Option<u64>,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/cache-config",
response = "ReadTransitCacheConfigurationResponse",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct ReadTransitCacheConfigurationRequest {
#[endpoint(skip)]
pub mount: String,
}
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
path = "{self.mount}/wrapping_key",
response = "GetWrappingKeyResponse",
builder = "true"
)]
#[builder(setter(into), default)]
pub struct GetWrappingKeyRequest {
#[endpoint(skip)]
pub mount: String,
}