ic_backup/model/ic_update_response/
mod.rs1use crate::model::{
4 artifacts::ArtifactChecksumRecord, attempt_journal::MAX_OPERATION_ATTEMPTS,
5 operation_plan::PlanContextRecord,
6};
7use std::fmt;
8
9#[derive(Clone)]
11pub struct IcUpdateResponseInput {
12 pub authority: ArtifactChecksumRecord,
14 pub mutation_attempt: u32,
16 pub context: PlanContextRecord,
18 pub target: String,
20 pub reply: Vec<u8>,
22 pub evidence: ArtifactChecksumRecord,
24}
25
26impl IcUpdateResponseInput {
27 pub(crate) fn admit<E>(
28 &mut self,
29 max_reply_bytes: usize,
30 invalid_attempt: E,
31 reply_too_large: E,
32 invalid_target: E,
33 ) -> Result<(), E> {
34 if self.mutation_attempt == 0 || self.mutation_attempt > MAX_OPERATION_ATTEMPTS {
35 return Err(invalid_attempt);
36 }
37 if self.reply.len() > max_reply_bytes {
38 return Err(reply_too_large);
39 }
40 self.target =
41 crate::model::principal::canonical_text(&self.target).ok_or(invalid_target)?;
42 Ok(())
43 }
44
45 pub(crate) fn fmt_redacted(
46 &self,
47 formatter: &mut fmt::Formatter<'_>,
48 name: &str,
49 ) -> fmt::Result {
50 formatter
51 .debug_struct(name)
52 .field("authority", &self.authority)
53 .field("mutation_attempt", &self.mutation_attempt)
54 .field("target", &self.target)
55 .field("reply_bytes", &self.reply.len())
56 .finish_non_exhaustive()
57 }
58}
59
60#[cfg(test)]
61mod tests;