| 22 | } |
| 23 | |
| 24 | fn decode(value: &str, path: bool) -> Result<String, IriError> { |
| 25 | let mut decoded = Vec::new(); |
| 26 | let bytes = value.as_bytes(); |
| 27 | let mut i = 0; |
| 28 | while i < bytes.len() { |
| 29 | if bytes[i] == b'%' { |
| 30 | let hex = value |
| 31 | .get(i + 1..i + 3) |
| 32 | .ok_or_else(|| IriError(value.into()))?; |
| 33 | decoded.push(u8::from_str_radix(hex, 16).map_err(|_| IriError(value.into()))?); |
| 34 | i += 3; |
| 35 | } else { |
| 36 | decoded.push(bytes[i]); |
| 37 | i += 1; |
| 38 | } |
| 39 | } |
| 40 | let decoded = String::from_utf8(decoded).map_err(|_| IriError(value.into()))?; |
| 41 | if encode(&decoded, path) != value { |
| 42 | return Err(IriError(value.into())); |
| 43 | } |
| 44 | Ok(decoded) |
| 45 | } |
| 46 | |
| 47 | pub fn mint_project(project: &ProjectId) -> String { |
| 48 | project.to_urn() |