about summary refs log tree commit diff
path: root/server/src/parsing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/parsing.rs')
-rw-r--r--server/src/parsing.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/src/parsing.rs b/server/src/parsing.rs
new file mode 100644
index 0000000..40a855a
--- /dev/null
+++ b/server/src/parsing.rs
@@ -0,0 +1,17 @@
+use base64::{encode_config, URL_SAFE_NO_PAD};
+use crc32fast::Hasher;
+use url::{ParseError, Url};
+
+pub fn make_url(given_url: &str) -> Result<String, ParseError> {
+    let parsed_url = Url::parse(given_url)?;
+    Ok(parsed_url.into_string())
+}
+
+pub fn get_hash_from_string(to_hash: &String) -> String {
+    let mut hasher = Hasher::new();
+    hasher.update(to_hash.as_bytes());
+    encode_config(hasher.finalize().to_ne_bytes(), URL_SAFE_NO_PAD)
+        .chars()
+        .take(3)
+        .collect()
+}