#![allow(unused_qualifications)]
use crate::types::types::CryptoContext;
pub trait ZeroTrustAuthenticable {
type Proof;
type Error;
fn generate_proof(&self, challenge: &[u8]) -> std::result::Result<Self::Proof, Self::Error>;
fn verify_proof(
&self,
proof: &Self::Proof,
challenge: &[u8],
) -> std::result::Result<bool, Self::Error>;
}
pub trait ProofOfPossession {
type Pop;
type Error;
fn generate_pop(&self) -> std::result::Result<Self::Pop, Self::Error>;
fn verify_pop(&self, pop: &Self::Pop) -> std::result::Result<bool, Self::Error>;
}
pub trait ContinuousVerifiable {
type Error;
fn verify_continuously(&self) -> std::result::Result<VerificationStatus, Self::Error>;
fn reauthenticate(&self) -> std::result::Result<(), Self::Error>;
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(kani, derive(kani::Arbitrary))]
pub enum VerificationStatus {
Verified,
Expired,
Failed,
Pending,
}
impl VerificationStatus {
#[must_use]
pub fn is_verified(&self) -> bool {
matches!(self, Self::Verified)
}
}
#[cfg(kani)]
mod kani_proofs {
use super::*;
#[kani::proof]
fn verification_status_is_verified_iff_verified() {
let status: VerificationStatus = kani::any();
let method = status.is_verified();
let expected = matches!(status, VerificationStatus::Verified);
kani::assert(method == expected, "is_verified() iff Verified variant");
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum HardwareType {
Cpu,
Gpu,
Fpga,
Tpu,
Sgx,
}
#[derive(Debug, Clone)]
pub struct HardwareInfo {
pub available_accelerators: Vec<HardwareType>,
pub preferred_accelerator: Option<HardwareType>,
pub capabilities: HardwareCapabilities,
}
#[derive(Debug, Clone)]
pub struct HardwareCapabilities {
pub simd_support: bool,
pub aes_ni: bool,
pub threads: usize,
pub memory: usize,
}
impl HardwareInfo {
#[must_use]
pub fn best_accelerator(&self) -> Option<&HardwareType> {
self.preferred_accelerator.as_ref().or_else(|| self.available_accelerators.first())
}
#[must_use]
pub fn summary(&self) -> String {
format!(
"Available: {:?}, Preferred: {:?}, Capabilities: {:?}",
self.available_accelerators, self.preferred_accelerator, self.capabilities
)
}
}
pub trait SchemeSelector {
type Error;
fn select_encryption_scheme(
&self,
data: &[u8],
ctx: &CryptoContext,
) -> std::result::Result<String, Self::Error>;
fn select_signature_scheme(
&self,
ctx: &CryptoContext,
) -> std::result::Result<String, Self::Error>;
fn analyze_data_characteristics(&self, data: &[u8]) -> DataCharacteristics;
}
#[derive(Debug, Clone)]
pub struct DataCharacteristics {
pub size: usize,
pub entropy: f64,
pub pattern_type: PatternType,
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum PatternType {
Random,
Structured,
Repetitive,
Text,
Binary,
}