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