Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust): Replace base64-url with base64 #234

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/catalyst-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ orx-concurrent-vec = { version = "3.2.0", features = ["serde"] }
pallas-crypto = { version = "0.30.1", git = "https://github.com/input-output-hk/catalyst-pallas.git", rev = "9b5183c8b90b90fe2cc319d986e933e9518957b3" }
serde = { version = "1.0.217", features = ["derive", "rc"] }
thiserror = "2.0.11"
base64-url = "3.0.0"
base64 = "0.22.1"
uuid = { version = "1.12.0", features = ["v4", "v7", "serde"] }
chrono = "0.4.39"
fmmap = { version = "0.4.0", features = ["sync", "tokio"] }
Expand Down
2 changes: 1 addition & 1 deletion rust/catalyst-types/src/id_uri/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum IdUriError {
/// Role 0 Key in path is invalid
InvalidRole0Key,
/// Role 0 Key in path is not encoded correctly
InvalidRole0KeyEncoding(#[from] base64_url::base64::DecodeError),
InvalidRole0KeyEncoding(#[from] base64::DecodeError),
/// Role Index is invalid
InvalidRole,
/// Role Index is not encoded correctly
Expand Down
10 changes: 6 additions & 4 deletions rust/catalyst-types/src/id_uri/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
str::FromStr,
};

use base64::Engine;
use chrono::{DateTime, Duration, Utc};
use ed25519_dalek::VerifyingKey;
use fluent_uri::{
Expand Down Expand Up @@ -550,8 +551,8 @@ impl FromStr for IdUri {

// Decode and validate the Role0 Public key from the path
let encoded_role0_key = path.get(1).ok_or(errors::IdUriError::InvalidRole0Key)?;
let decoded_role0_key =
base64_url::decode(encoded_role0_key.decode().into_string_lossy().as_ref())?;
let decoded_role0_key = base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(encoded_role0_key.decode().into_string_lossy().as_ref())?;
let role0_pk = crate::conversion::vkey_from_bytes(&decoded_role0_key)
.or(Err(errors::IdUriError::InvalidRole0Key))?;

Expand Down Expand Up @@ -638,7 +639,7 @@ impl Display for IdUri {
f,
"{}/{}",
self.network,
base64_url::encode(self.role0_pk.as_bytes()),
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(self.role0_pk.as_bytes()),
)?;

// Role and Rotation are only serialized if its NOT and ID or they are not the defaults.
Expand Down Expand Up @@ -667,6 +668,7 @@ impl TryFrom<&[u8]> for IdUri {

#[cfg(test)]
mod tests {
use base64::Engine;
use ed25519_dalek::SigningKey;
use rand::rngs::OsRng;

Expand Down Expand Up @@ -711,7 +713,7 @@ mod tests {
let mut csprng = OsRng;
let signing_key: SigningKey = SigningKey::generate(&mut csprng);
let vk = signing_key.verifying_key();
let encoded_vk = base64_url::encode(vk.as_bytes());
let encoded_vk = base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(vk.as_bytes());
assert_eq!(encoded_vk, "1234");
}
}
2 changes: 1 addition & 1 deletion rust/signed_doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jsonpath-rust = "0.7.5"
futures = "0.3.31"

[dev-dependencies]
base64-url = "3.0.0"
base64 = "0.22.1"
rand = "0.8.5"
tokio = { version = "1.42.0", features = [ "macros" ] }

Expand Down
3 changes: 2 additions & 1 deletion rust/signed_doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl TryFrom<CatalystSignedDocument> for Vec<u8> {
mod tests {
use std::str::FromStr;

use base64::Engine;
use ed25519_dalek::{SigningKey, VerifyingKey};
use metadata::{ContentEncoding, ContentType};
use rand::rngs::OsRng;
Expand Down Expand Up @@ -357,7 +358,7 @@ mod tests {

let kid_str = format!(
"id.catalyst://cardano/{}/0/0",
base64_url::encode(pk.as_bytes())
base64::engine::general_purpose::URL_SAFE_NO_PAD.encode(pk.as_bytes())
);

let kid = IdUri::from_str(&kid_str).unwrap();
Expand Down