| 1 |
//! Implements the "always trust" model. |
| 2 |
|
| 3 |
use std::{ |
| 4 |
time::SystemTime, |
| 5 |
sync::Arc, |
| 6 |
}; |
| 7 |
|
| 8 |
use anyhow::Result; |
| 9 |
|
| 10 |
use sequoia_openpgp as openpgp; |
| 11 |
use openpgp::{ |
| 12 |
Fingerprint, |
| 13 |
packet::UserID, |
| 14 |
policy::Policy, |
| 15 |
}; |
| 16 |
|
| 17 |
use sequoia_cert_store as cert_store; |
| 18 |
use cert_store::LazyCert; |
| 19 |
|
| 20 |
use crate::{ |
| 21 |
Config, |
| 22 |
common::Common, |
| 23 |
trust::{ |
| 24 |
Model, |
| 25 |
ModelViewAt, |
| 26 |
Query, |
| 27 |
TrustModel, |
| 28 |
Validity, |
| 29 |
ValidityLevel, |
| 30 |
}, |
| 31 |
}; |
| 32 |
|
| 33 |
/// The "always trust" model. |
| 34 |
#[derive(Default, Debug)] |
| 35 |
pub struct Always(()); |
| 36 |
|
| 37 |
impl Model for Always { |
| 38 |
fn with_policy_and_precompute<'a, 'store>( |
| 39 |
&self, config: &'a Config<'store>, |
| 40 |
time: Option<SystemTime>, |
| 41 |
_: bool) |
| 42 |
-> Result<Box<dyn ModelViewAt<'a, 'store> + 'a>> |
| 43 |
where 'store: 'a |
| 44 |
{ |
| 45 |
Ok(Box::new(AlwaysViewAt { |
| 46 |
config, |
| 47 |
time: time.unwrap_or_else(move || config.now()), |
| 48 |
})) |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
struct AlwaysViewAt<'a, 'store> { |
| 53 |
config: &'a Config<'store>, |
| 54 |
time: SystemTime, |
| 55 |
} |
| 56 |
|
| 57 |
impl<'a, 'store> ModelViewAt<'a, 'store> for AlwaysViewAt<'a, 'store> { |
| 58 |
fn kind(&self) -> TrustModel { |
| 59 |
TrustModel::Always |
| 60 |
} |
| 61 |
|
| 62 |
fn time(&self) -> SystemTime { |
| 63 |
self.time |
| 64 |
} |
| 65 |
|
| 66 |
fn policy(&self) -> &dyn Policy { |
| 67 |
self.config.policy() |
| 68 |
} |
| 69 |
|
| 70 |
fn validity(&self, _: &UserID, _: &Fingerprint) |
| 71 |
-> Result<Validity> { |
| 72 |
// Always unknown validity, see tdb_get_ownertrust. |
| 73 |
Ok(ValidityLevel::Unknown.into()) |
| 74 |
} |
| 75 |
|
| 76 |
fn lookup(&self, query: &Query) -> Result<Vec<(Validity, Arc<LazyCert<'store>>)>> { |
| 77 |
Ok(self.config.keydb.lookup_candidates(self.config, query)? |
| 78 |
.into_iter() |
| 79 |
.map(|c| (ValidityLevel::Unknown.into(), c)) |
| 80 |
.collect()) |
| 81 |
} |
| 82 |
} |