pub mod hmac_sign;
mod cryptographic;
use std::path::PathBuf;
use crate::{error::CryptError, FileMetadata};
use std::fmt;
#[derive(PartialEq, Debug, Clone)]
pub struct CipherAES {
pub infos: CryptographicInformation,
pub sharedsecret: Vec<u8>,
}
impl fmt::Display for CipherAES {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CipherAES with the following Cryptographic Informations: {}", self.infos.metadata)
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct CipherAesGcmSiv {
pub infos: CryptographicInformation,
pub sharedsecret: Vec<u8>,
pub iv: Vec<u8>,
}
impl fmt::Display for CipherAesGcmSiv {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CipherAesGcmSiv with the following Cryptographic Informations: {}", self.infos.metadata)
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct CipherAesCtr {
pub infos: CryptographicInformation,
pub sharedsecret: Vec<u8>,
pub iv: Vec<u8>,
}
impl fmt::Display for CipherAesCtr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CipherAesCtr with the following Cryptographic Informations: {}", self.infos.metadata)
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct CipherAesXts {
pub infos: CryptographicInformation,
pub sharedsecret: Vec<u8>,
}
impl fmt::Display for CipherAesXts {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CipherAesXts with the following Cryptographic Informations: {}", self.infos.metadata)
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct CipherChaCha {
pub infos: CryptographicInformation,
pub nonce: [u8; 24],
pub sharedsecret: Vec<u8>,
}
impl fmt::Display for CipherChaCha {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CipherChaCha with the following Cryptographic Informations {}", self.infos.metadata)
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct CipherChaChaPoly {
pub infos: CryptographicInformation,
pub nonce: [u8; 24],
pub sharedsecret: Vec<u8>,
}
impl fmt::Display for CipherChaChaPoly {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "CipherChaCha with the following Cryptographic Informations {}", self.infos.metadata)
}
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum CryptographicMechanism {
AES,
AesGcmSiv,
AesCtr,
AesXts,
XChaCha20Poly1305,
XChaCha20,
}
impl fmt::Display for CryptographicMechanism {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mechanism = match self {
CryptographicMechanism::AES => "AES",
CryptographicMechanism::AesGcmSiv => "AES-GCM-SIV",
CryptographicMechanism::AesCtr => "AES-CTR",
CryptographicMechanism::AesXts => "AES-XTS",
CryptographicMechanism::XChaCha20Poly1305 => "XChaCha20Poly1305",
CryptographicMechanism::XChaCha20 => "XChaCha20",
};
write!(f, "{}", mechanism)
}
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum KeyEncapMechanism {
Kyber1024,
Kyber768,
Kyber512,
}
impl fmt::Display for KeyEncapMechanism {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mechanism = match self {
KeyEncapMechanism::Kyber1024 => "Kyber1024",
KeyEncapMechanism::Kyber768 => "Kyber768",
KeyEncapMechanism::Kyber512 => "Kyber512",
};
write!(f, "{}", mechanism)
}
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum ContentType {
Message,
File,
RawData,
Device,
}
impl fmt::Display for ContentType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let content_type = match self {
ContentType::Message => "Message",
ContentType::File => "File",
ContentType::RawData => "RawData",
ContentType::Device => "Device",
};
write!(f, "{}", content_type)
}
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub enum Process {
Encryption,
Decryption,
}
impl fmt::Display for Process {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let process = match self {
Process::Encryption => "Encryption",
Process::Decryption => "Decryption",
};
write!(f, "{}", process)
}
}
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct CryptographicMetadata {
pub process: Process,
pub encryption_type: CryptographicMechanism,
pub key_type: KeyEncapMechanism,
pub content_type: ContentType,
}
impl fmt::Display for CryptographicMetadata {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Process: {}\nEncryption Type: {}\nKey Type: {}\nContent Type: {}", self.process, self.encryption_type, self.key_type, self.content_type)
}
}
#[derive(PartialEq, Debug, Clone)]
pub struct CryptographicInformation {
pub content: Vec<u8>,
pub passphrase: Vec<u8>,
pub metadata: CryptographicMetadata,
pub safe: bool,
pub location: Option<FileMetadata>,
}
impl fmt::Display for CryptographicInformation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Cryptographic Information:\n\
-\tMetadata:\t\t{}\n\
-\tContent Length:\t{} bytes\n",
self.metadata,
self.content.len())
}
}