aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/lib.rs')
-rw-r--r--rust/src/lib.rs26
1 files changed, 6 insertions, 20 deletions
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 9de94d86..86e367e4 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -33,7 +33,12 @@ mod errors {
Uuid(::uuid::ParseError);
Io(::std::io::Error) #[cfg(unix)];
Serde(::serde_json::Error);
- Base32(::data_encoding::DecodeError);
+ }
+ errors {
+ InvalidFatcatId(id: String) {
+ description("invalid fatcat identifier syntax")
+ display("invalid fatcat identifier (expect 26-char base32 encoded): {}", id)
+ }
}
}
}
@@ -49,7 +54,6 @@ use dotenv::dotenv;
use iron::middleware::AfterMiddleware;
use iron::{Request, Response};
use std::env;
-use data_encoding::BASE32_NOPAD;
#[cfg(feature = "postgres")]
embed_migrations!("../migrations/");
@@ -103,21 +107,3 @@ impl AfterMiddleware for XClacksOverheadMiddleware {
Ok(res)
}
}
-
-/// Convert fatcat IDs (base32 strings) to UUID
-pub fn fcid2uuid(fcid: &str) -> Result<uuid::Uuid> {
- if fcid.len() != 20 {
- bail!("invalid fatcat ID (expecting 20-chars of base32");
- }
- let mut raw = vec![0; 16];
- BASE32_NOPAD.decode_mut(fcid.to_uppercase().as_bytes(), &mut raw)
- .map_err(|dp| dp.error)?;
- // unwrap() is safe here, because we know raw is always 16 bytes
- Ok(uuid::Uuid::from_bytes(&raw).unwrap())
-}
-
-/// Convert UUID to fatcat ID string (base32 encoded)
-pub fn uuid2fcid(id: &uuid::Uuid) -> String {
- let raw = id.as_bytes();
- BASE32_NOPAD.encode(raw).to_lowercase()
-}