summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2023-01-03 10:46:25 -0500
committerGitHub <noreply@github.com>2023-01-03 10:46:25 -0500
commit139f736f79f890d5a73e85aaad8e9e8d4ffb28f9 (patch)
tree9d86aaffaa07114f75793a01f98d852eb7e4a88d
parent2d4ee168d7eae0afcce356a3f8135294e6d7fe6f (diff)
parentb4667c1b31ac6c8754d78835230d2dcde95b0387 (diff)
downloadostree-139f736f79f890d5a73e85aaad8e9e8d4ffb28f9.tar.gz
Merge pull request #2799 from jeamland/replace-radix64
Replace the radix64 crate with base64
-rw-r--r--Cargo.toml2
-rw-r--r--rust-bindings/src/checksum.rs37
2 files changed, 22 insertions, 17 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 31822af5..726cf10b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -38,6 +38,7 @@ path = "rust-bindings/tests/tests.rs"
members = [".", "rust-bindings/sys"]
[dependencies]
+base64 = "0.20.0"
bitflags = "1.2.1"
cap-std = { version = "1.0", optional = true}
io-lifetimes = { version = "1.0", optional = true}
@@ -47,7 +48,6 @@ glib = "0.16"
hex = "0.4.2"
libc = "0.2"
once_cell = "1.4.0"
-radix64 = "0.6.2"
thiserror = "1.0.20"
[dev-dependencies]
diff --git a/rust-bindings/src/checksum.rs b/rust-bindings/src/checksum.rs
index 4cc98164..d9e522f3 100644
--- a/rust-bindings/src/checksum.rs
+++ b/rust-bindings/src/checksum.rs
@@ -1,23 +1,28 @@
+use base64::{
+ alphabet::Alphabet,
+ engine::fast_portable::{FastPortable, FastPortableConfig},
+ engine::DecodePaddingMode,
+};
use glib::ffi::{g_free, g_malloc0, gpointer};
use glib::translate::{FromGlibPtrFull, FromGlibPtrNone};
-use once_cell::sync::OnceCell;
+use once_cell::sync::Lazy;
use std::ptr::copy_nonoverlapping;
const BYTES_LEN: usize = ffi::OSTREE_SHA256_DIGEST_LEN as usize;
-static BASE64_CONFIG: OnceCell<radix64::CustomConfig> = OnceCell::new();
-
-fn base64_config() -> &'static radix64::CustomConfig {
- BASE64_CONFIG.get_or_init(|| {
- radix64::configs::CustomConfigBuilder::with_alphabet(
- // modified base64 alphabet used by ostree (uses _ instead of /)
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_",
- )
- .no_padding()
- .build()
- .unwrap()
- })
-}
+static BASE64_ENGINE: Lazy<FastPortable> = Lazy::new(|| {
+ // modified base64 alphabet used by ostree (uses _ instead of /)
+ let alphabet =
+ Alphabet::from_str("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_")
+ .expect("bad base64 alphabet");
+
+ FastPortable::from(
+ &alphabet,
+ FastPortableConfig::new()
+ .with_encode_padding(false)
+ .with_decode_padding_mode(DecodePaddingMode::Indifferent),
+ )
+});
/// Error returned from parsing a checksum.
#[derive(Debug, thiserror::Error)]
@@ -61,7 +66,7 @@ impl Checksum {
/// Create a `Checksum` from a base64-encoded String.
pub fn from_base64(b64_checksum: &str) -> Result<Checksum, ChecksumError> {
let mut checksum = Checksum::zeroed();
- match base64_config().decode_slice(b64_checksum, checksum.as_mut()) {
+ match base64::decode_engine_slice(b64_checksum, checksum.as_mut(), &*BASE64_ENGINE) {
Ok(BYTES_LEN) => Ok(checksum),
Ok(_) => Err(ChecksumError::InvalidBase64String),
Err(_) => Err(ChecksumError::InvalidBase64String),
@@ -75,7 +80,7 @@ impl Checksum {
/// Convert checksum to base64 string.
pub fn to_base64(&self) -> String {
- base64_config().encode(self.as_slice())
+ base64::encode_engine(self.as_slice(), &*BASE64_ENGINE)
}
/// Create a `Checksum` value, taking ownership of the given memory location.