Skip to content

Instantly share code, notes, and snippets.

@jcgruenhage
Created July 13, 2023 09:29
Show Gist options
  • Save jcgruenhage/b8dba2f06e2071b0609eedd992bf05bb to your computer and use it in GitHub Desktop.
Save jcgruenhage/b8dba2f06e2071b0609eedd992bf05bb to your computer and use it in GitHub Desktop.
Small rust script for decoding the ID from a hedgedoc URL path to the uuid used in the database.
#!/usr/bin/env cargo
//! ```cargo
//! [dependencies]
//! anyhow = "1"
//! base64 = "0.21"
//! hex = "0.4"
//! ```
use base64::Engine;
fn main() -> anyhow::Result<()> {
let id = "put your hedgedoc ID here";
let decoded = base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(id)?;
let encoded = hex::encode(decoded);
let mut parts = vec![];
parts.push(encoded[0..8].to_string());
parts.push(encoded[8..12].to_string());
parts.push(encoded[12..16].to_string());
parts.push(encoded[16..20].to_string());
parts.push(encoded[20..32].to_string());
println!("{}", parts.join("-"));
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment