(tag: u8, bytes: &[u8], field: &str)
| 150 | } |
| 151 | |
| 152 | fn decode_optional_hash(tag: u8, bytes: &[u8], field: &str) -> PristineResult<Option<Hash>> { |
| 153 | match tag { |
| 154 | 0 => { |
| 155 | if bytes.iter().any(|byte| *byte != 0) { |
| 156 | return Err(working_copy_serialization_error(format!( |
| 157 | "absent {field} contains non-zero bytes" |
| 158 | ))); |
| 159 | } |
| 160 | Ok(None) |
| 161 | } |
| 162 | 1 => Ok(Some(Hash::from_bytes(bytes.try_into().map_err(|_| { |
| 163 | working_copy_serialization_error(format!("invalid {field} bytes")) |
| 164 | })?))), |
| 165 | other => Err(working_copy_serialization_error(format!( |
| 166 | "invalid {field} presence tag {other}" |
| 167 | ))), |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | fn working_copy_serialization_error(message: impl Into<String>) -> PristineError { |
| 172 | PristineError::Serialization { |
no test coverage detected