1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::{SecureChannelTrustInfo, TrustPolicy};
use ockam_core::Result;
#[derive(Clone)]
pub struct AllTrustPolicy<F: TrustPolicy, S: TrustPolicy> {
first: F,
second: S,
}
impl<F: TrustPolicy, S: TrustPolicy> AllTrustPolicy<F, S> {
pub fn new(first: F, second: S) -> Self {
AllTrustPolicy { first, second }
}
}
impl<F: TrustPolicy, S: TrustPolicy> TrustPolicy for AllTrustPolicy<F, S> {
fn check(&self, trust_info: &SecureChannelTrustInfo) -> Result<bool> {
Ok(self.first.check(trust_info)? && self.second.check(trust_info)?)
}
}
#[cfg(test)]
mod test {
use crate::{ConjunctionTrustPolicy, ProfileIdentifier, SecureChannelTrustInfo, TrustPolicy};
use ockam_core::Result;
#[test]
fn test() {
#[derive(Clone)]
struct TrustPolicyStub(bool);
impl TrustPolicy for TrustPolicyStub {
fn check(&self, _trust_info: &SecureChannelTrustInfo) -> Result<bool> {
Ok(self.0)
}
}
let id = ProfileIdentifier::random();
let trust_info = SecureChannelTrustInfo::new(id);
assert!(TrustPolicyStub(true)
.and(TrustPolicyStub(true))
.check(&trust_info)
.unwrap());
assert!(!TrustPolicyStub(true)
.and(TrustPolicyStub(false))
.check(&trust_info)
.unwrap());
assert!(!TrustPolicyStub(false)
.and(TrustPolicyStub(true))
.check(&trust_info)
.unwrap());
assert!(!TrustPolicyStub(false)
.and(TrustPolicyStub(false))
.check(&trust_info)
.unwrap());
}
}