diff --git a/Cargo.toml b/Cargo.toml index cfd583f..98a51ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.64" version = "0.0.7-alpha" [dependencies] -base64 = "0.13" +base64 = "0.21" byteorder = "1.4" const-str = "0.5" serde = { version = "1.0", features = ["derive"] } diff --git a/src/imp/http_proxy.rs b/src/imp/http_proxy.rs index e3220e0..72068b5 100644 --- a/src/imp/http_proxy.rs +++ b/src/imp/http_proxy.rs @@ -12,7 +12,7 @@ use serde_json::Deserializer; use crate::errors::{DecLibraryError, DecUseError}; use crate::imp::content_type; use crate::imp::hyper_proxy::HyperHttpClient; -use crate::imp::other::converge; +use crate::imp::other::{base64_encode, converge}; use crate::model::{RegistryAuth, RegistryConfig}; use crate::responses::ErrorResponse; @@ -140,7 +140,7 @@ impl DockerEngineHttpClient { let json = serde_json::to_string(&auth) .map_err(DecLibraryError::RegistryAuthJsonEncodingError)?; - Ok(Some(base64::encode(json))) + Ok(Some(base64_encode(json))) } } } @@ -153,7 +153,7 @@ impl DockerEngineHttpClient { let json = serde_json::to_string(registry_config) .map_err(DecLibraryError::RegistryAuthJsonEncodingError)?; - Ok(Some(base64::encode(json))) + Ok(Some(base64_encode(json))) } } } diff --git a/src/imp/other.rs b/src/imp/other.rs index 38932d9..15022cb 100644 --- a/src/imp/other.rs +++ b/src/imp/other.rs @@ -1,4 +1,13 @@ + +/// Convenience wrapper over base64 crate's breaking changes +pub(crate) fn base64_encode>(input: T) -> String { + use base64::engine::general_purpose::STANDARD; + use base64::Engine; + + STANDARD.encode(input) +} + /// Some functions convert/extract input parameters that represent failure information. /// That information is converted to an error result type. /// @@ -13,6 +22,20 @@ pub(crate) fn converge(result: Result) -> A { } } +#[cfg(test)] +mod test_base64_encode { + use super::base64_encode; + + //noinspection SpellCheckingInspection + #[test] + fn encodes() { + let input: [u8; 4] = [2, 3, 4, 5]; + + let expected = "AgMEBQ=="; + assert_eq!(expected, base64_encode(input)); + } +} + #[cfg(test)] mod test_converge { use super::converge;