fix(uriproxy): use URL_SAFE base64 alphabet

This commit is contained in:
əlemi 2024-05-20 07:04:29 +02:00
parent f9e021a37a
commit 4a17c12b58
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 6 additions and 6 deletions

View file

@ -124,7 +124,7 @@ impl Context {
uriproxy::uri(self.base(), UriClass::Context, id)
}
/// get bare id, which is uuid for local stuff and ~{uri|base64} for remote stuff
/// get bare id, which is uuid for local stuff and +{uri|base64} for remote stuff
pub fn id(&self, full_id: &str) -> String {
if self.is_local(full_id) {
uriproxy::decompose_id(full_id)

View file

@ -21,8 +21,8 @@ impl AsRef<str> for UriClass {
/// unpack uri in id if valid, otherwise compose full uri with "{base}/{entity}/{id}"
pub fn uri(base: &str, entity: UriClass, id: &str) -> String {
if id.starts_with('~') { // ready-to-use base64-encoded id
if let Ok(bytes) = base64::prelude::BASE64_STANDARD.decode(id) {
if id.starts_with('+') { // ready-to-use base64-encoded id
if let Ok(bytes) = base64::prelude::BASE64_URL_SAFE.decode(id) {
if let Ok(uri) = std::str::from_utf8(&bytes) {
return uri.to_string();
}
@ -40,8 +40,8 @@ pub fn decompose_id(full_id: &str) -> String {
.to_string()
}
/// encode with base64 remote url and prefix it with ~
/// encode with base64 remote url and prefix it with +
pub fn compact_id(uri: &str) -> String {
let encoded = base64::prelude::BASE64_STANDARD.encode(uri.as_bytes());
format!("~{encoded}")
let encoded = base64::prelude::BASE64_URL_SAFE.encode(uri.as_bytes());
format!("+{encoded}")
}