about summary refs log tree commit diff
path: root/server/src/parsing.rs
blob: 3e1b15e39ad03d38c015a99c3fbb8d56aa5932dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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: &str) -> 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()
}