ic_backup/policy/response_identity/
mod.rs1use crate::model::{
4 artifacts::ArtifactChecksumRecord, ic_update_response::IcUpdateResponseInput,
5 operation_plan::PlanContextRecord,
6};
7
8pub(super) struct ResponseIdentity<'a> {
9 pub authority: &'a ArtifactChecksumRecord,
10 pub mutation_attempt: u32,
11 pub context: &'a PlanContextRecord,
12 pub target: &'a str,
13}
14
15impl<'a> From<&'a IcUpdateResponseInput> for ResponseIdentity<'a> {
16 fn from(input: &'a IcUpdateResponseInput) -> Self {
17 Self {
18 authority: &input.authority,
19 mutation_attempt: input.mutation_attempt,
20 context: &input.context,
21 target: &input.target,
22 }
23 }
24}
25
26impl ResponseIdentity<'_> {
27 pub fn compare(&self, expected: &Self) -> Result<(), ResponseIdentityMismatch> {
28 if self.authority != expected.authority {
29 return Err(ResponseIdentityMismatch::Authority);
30 }
31 if self.mutation_attempt != expected.mutation_attempt {
32 return Err(ResponseIdentityMismatch::Attempt);
33 }
34 if self.context != expected.context {
35 return Err(ResponseIdentityMismatch::Context);
36 }
37 if self.target != expected.target {
38 return Err(ResponseIdentityMismatch::Target);
39 }
40 Ok(())
41 }
42}
43
44#[derive(Debug, thiserror::Error, Eq, PartialEq)]
46pub enum ResponseIdentityMismatch {
47 #[error("response authority differs")]
49 Authority,
50 #[error("response attempt differs")]
52 Attempt,
53 #[error("response context differs")]
55 Context,
56 #[error("response target differs")]
58 Target,
59}