| 35 | pub const REJECTION_REASON: &str = "reason"; |
| 36 | |
| 37 | pub fn hash_from_proto(hash: Option<&pb::Hash>) -> Result<Hash, String> { |
| 38 | let hash = hash.ok_or("hash is required")?; |
| 39 | if hash.algorithm != pb::HashAlgorithm::Blake3 as i32 && hash.algorithm != 0 { |
| 40 | return Err("only blake3 hashes are accepted".to_string()); |
| 41 | } |
| 42 | let bytes: [u8; 32] = hash |
| 43 | .value |
| 44 | .as_slice() |
| 45 | .try_into() |
| 46 | .map_err(|_| "a hash is exactly 32 bytes".to_string())?; |
| 47 | Ok(Hash::from_bytes(bytes)) |
| 48 | } |
| 49 | |
| 50 | fn versioned(schema: &str, payload: Vec<u8>) -> pb::VersionedBytes { |
| 51 | pb::VersionedBytes { |