use alloc::borrow::Cow;
use alloc::string::ToString;
use super::{FetchContext, KeyFetch, RawKey};
use crate::Result;
use crate::error::Error;
#[derive(Debug, Default, Clone, Copy)]
pub struct TpmFetch;
impl KeyFetch for TpmFetch {
fn fetch(&self, _ctx: &FetchContext) -> Result<RawKey> {
Err(Error::Acquisition {
source: Cow::Borrowed("tpm"),
reason:
"TPM 2.0 acquisition is detection-only in 1.0; full integration arrives in the \
1.x release line. Use detect_tee_capabilities() to probe for TPM presence."
.to_string(),
})
}
fn describe(&self) -> Cow<'_, str> {
Cow::Borrowed("tpm")
}
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used)]
mod tests {
use super::*;
#[test]
fn fetch_returns_detection_only_error() {
let err = TpmFetch.fetch(&FetchContext::new("k")).unwrap_err();
match err {
Error::Acquisition { source, reason } => {
assert_eq!(source, "tpm");
assert!(reason.contains("detection-only"));
}
other => panic!("expected Acquisition, got {other:?}"),
}
}
#[test]
fn describe_returns_tpm() {
assert_eq!(TpmFetch.describe(), "tpm");
}
}