Skip to content

Commit

Permalink
Upgrade base64-simd to 0.8 (smithy-lang#2384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nugine authored Feb 16, 2023
1 parent f7ac844 commit 42671dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ itoa = "1.0.0"
num-integer = "0.1.44"
ryu = "1.0.5"
time = { version = "0.3.4", features = ["parsing"] }
base64-simd = "0.7"
base64-simd = "0.8"

[dev-dependencies]
base64 = "0.13.0"
Expand Down
15 changes: 5 additions & 10 deletions rust-runtime/aws-smithy-types/src/base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

//! A thin wrapper over `base64-simd`
//! A thin wrapper over [`base64-simd`](https://docs.rs/base64-simd/)

use base64_simd::Base64;
use base64_simd::STANDARD;
use std::error::Error;

/// Failure to decode a base64 value.
Expand All @@ -28,20 +28,15 @@ impl std::fmt::Display for DecodeError {
///
/// If input is not a valid base64 encoded string, this function will return `DecodeError`.
pub fn decode(input: impl AsRef<str>) -> Result<Vec<u8>, DecodeError> {
Base64::STANDARD
.decode_to_boxed_bytes(input.as_ref().as_bytes())
.map(|bytes| bytes.into_vec())
.map_err(DecodeError)
STANDARD.decode_to_vec(input.as_ref()).map_err(DecodeError)
}

/// Encode `input` into base64 using the standard base64 alphabet
pub fn encode(input: impl AsRef<[u8]>) -> String {
Base64::STANDARD
.encode_to_boxed_str(input.as_ref())
.into_string()
STANDARD.encode_to_string(input.as_ref())
}

/// Returns the base64 representation's length for the given `length` of data
pub fn encoded_length(length: usize) -> usize {
Base64::STANDARD.encoded_length(length)
STANDARD.encoded_length(length)
}

0 comments on commit 42671dd

Please sign in to comment.