use super::generate_key::GenerateKeyParams;
use super::{Command, Response};
use {
Adapter, Capability, CommandType, Domain, HmacAlg, ObjectId, ObjectLabel, Session, SessionError,
};
pub fn generate_hmac_key<A: Adapter>(
session: &mut Session<A>,
key_id: ObjectId,
label: ObjectLabel,
domains: Domain,
capabilities: Capability,
algorithm: HmacAlg,
) -> Result<ObjectId, SessionError> {
session
.send_command(GenHMACKeyCommand(GenerateKeyParams {
key_id,
label,
domains,
capabilities,
algorithm: algorithm.into(),
})).map(|response| response.key_id)
}
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GenHMACKeyCommand(pub(crate) GenerateKeyParams);
impl Command for GenHMACKeyCommand {
type ResponseType = GenHMACKeyResponse;
}
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct GenHMACKeyResponse {
pub key_id: ObjectId,
}
impl Response for GenHMACKeyResponse {
const COMMAND_TYPE: CommandType = CommandType::GenerateHMACKey;
}