Admit untrusted bytes before parsing, including duplicate-key/depth checks.
(bytes: &[u8])
| 152 | impl PublicationReview { |
| 153 | /// Admit untrusted bytes before parsing, including duplicate-key/depth checks. |
| 154 | pub fn parse(bytes: &[u8]) -> crate::Result<Self> { |
| 155 | if bytes.len() > MAX_BYTES { |
| 156 | return Err(crate::CanonicalError::Proof( |
| 157 | "publication review exceeds 1 MiB".into(), |
| 158 | )); |
| 159 | } |
| 160 | let review: Self = |
| 161 | serde_json::from_value(crate::jcs::admit_document(bytes)?).map_err(|error| { |
| 162 | crate::CanonicalError::Proof(format!("invalid publication review: {error}")) |
| 163 | })?; |
| 164 | if review.schema != SCHEMA && review.schema != LEGACY_SCHEMA { |
| 165 | return Err(crate::CanonicalError::Proof( |
| 166 | "unsupported publication review schema".into(), |
| 167 | )); |
| 168 | } |
| 169 | if review.schema == SCHEMA && review.subject.snapshot.is_none() { |
| 170 | return Err(crate::CanonicalError::Proof( |
| 171 | "v2 publication review requires retained source evidence".into(), |
| 172 | )); |
| 173 | } |
| 174 | if review.schema == LEGACY_SCHEMA && review.subject.snapshot.is_some() { |
| 175 | return Err(crate::CanonicalError::Proof( |
| 176 | "legacy publication review cannot claim v2 snapshot semantics".into(), |
| 177 | )); |
| 178 | } |
| 179 | Ok(review) |
| 180 | } |
| 181 | |
| 182 | /// The exact document passed through Atomic's common signing path. |
| 183 | pub fn value(&self) -> serde_json::Value { |
nothing calls this directly
no test coverage detected