summaryrefslogtreecommitdiffstats
path: root/vendor/base64/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/base64/src
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/base64/src')
-rw-r--r--vendor/base64/src/chunked_encoder.rs10
-rw-r--r--vendor/base64/src/decode.rs8
-rw-r--r--vendor/base64/src/encode.rs31
-rw-r--r--vendor/base64/src/engine/general_purpose/mod.rs2
-rw-r--r--vendor/base64/src/engine/mod.rs17
-rw-r--r--vendor/base64/src/engine/naive.rs3
-rw-r--r--vendor/base64/src/lib.rs14
-rw-r--r--vendor/base64/src/prelude.rs3
-rw-r--r--vendor/base64/src/read/decoder_tests.rs2
9 files changed, 50 insertions, 40 deletions
diff --git a/vendor/base64/src/chunked_encoder.rs b/vendor/base64/src/chunked_encoder.rs
index 69bc7457e..817b339f3 100644
--- a/vendor/base64/src/chunked_encoder.rs
+++ b/vendor/base64/src/chunked_encoder.rs
@@ -2,9 +2,9 @@ use crate::{
encode::add_padding,
engine::{Config, Engine},
};
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use alloc::string::String;
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use core::str;
/// The output mechanism for ChunkedEncoder's encoded bytes.
@@ -47,19 +47,19 @@ impl<'e, E: Engine + ?Sized> ChunkedEncoder<'e, E> {
}
// A really simple sink that just appends to a string
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub(crate) struct StringSink<'a> {
string: &'a mut String,
}
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
impl<'a> StringSink<'a> {
pub(crate) fn new(s: &mut String) -> StringSink {
StringSink { string: s }
}
}
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
impl<'a> Sink for StringSink<'a> {
type Error = ();
diff --git a/vendor/base64/src/decode.rs b/vendor/base64/src/decode.rs
index f590cbdd0..5230fd3c9 100644
--- a/vendor/base64/src/decode.rs
+++ b/vendor/base64/src/decode.rs
@@ -1,5 +1,5 @@
use crate::engine::{general_purpose::STANDARD, DecodeEstimate, Engine};
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use alloc::vec::Vec;
use core::fmt;
#[cfg(any(feature = "std", test))]
@@ -83,7 +83,7 @@ impl From<DecodeError> for DecodeSliceError {
///
/// See [Engine::decode].
#[deprecated(since = "0.21.0", note = "Use Engine::decode")]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
STANDARD.decode(input)
}
@@ -93,7 +93,7 @@ pub fn decode<T: AsRef<[u8]>>(input: T) -> Result<Vec<u8>, DecodeError> {
/// See [Engine::decode].
///Returns a `Result` containing a `Vec<u8>`.
#[deprecated(since = "0.21.0", note = "Use Engine::decode")]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub fn decode_engine<E: Engine, T: AsRef<[u8]>>(
input: T,
engine: &E,
@@ -104,7 +104,7 @@ pub fn decode_engine<E: Engine, T: AsRef<[u8]>>(
/// Decode from string reference as octets.
///
/// See [Engine::decode_vec].
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
#[deprecated(since = "0.21.0", note = "Use Engine::decode_vec")]
pub fn decode_engine_vec<E: Engine, T: AsRef<[u8]>>(
input: T,
diff --git a/vendor/base64/src/encode.rs b/vendor/base64/src/encode.rs
index 00ade7472..88e649924 100644
--- a/vendor/base64/src/encode.rs
+++ b/vendor/base64/src/encode.rs
@@ -1,10 +1,10 @@
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use alloc::string::String;
use core::fmt;
#[cfg(any(feature = "std", test))]
use std::error;
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use crate::engine::general_purpose::STANDARD;
use crate::engine::{Config, Engine};
use crate::PAD_BYTE;
@@ -14,7 +14,7 @@ use crate::PAD_BYTE;
/// See [Engine::encode].
#[allow(unused)]
#[deprecated(since = "0.21.0", note = "Use Engine::encode")]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub fn encode<T: AsRef<[u8]>>(input: T) -> String {
STANDARD.encode(input)
}
@@ -24,7 +24,7 @@ pub fn encode<T: AsRef<[u8]>>(input: T) -> String {
/// See [Engine::encode].
#[allow(unused)]
#[deprecated(since = "0.21.0", note = "Use Engine::encode")]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub fn encode_engine<E: Engine, T: AsRef<[u8]>>(input: T, engine: &E) -> String {
engine.encode(input)
}
@@ -34,7 +34,7 @@ pub fn encode_engine<E: Engine, T: AsRef<[u8]>>(input: T, engine: &E) -> String
/// See [Engine::encode_string].
#[allow(unused)]
#[deprecated(since = "0.21.0", note = "Use Engine::encode_string")]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub fn encode_engine_string<E: Engine, T: AsRef<[u8]>>(
input: T,
output_buf: &mut String,
@@ -94,25 +94,32 @@ pub(crate) fn encode_with_padding<E: Engine + ?Sized>(
///
/// Returns `None` if the encoded length can't be represented in `usize`. This will happen for
/// input lengths in approximately the top quarter of the range of `usize`.
-pub fn encoded_len(bytes_len: usize, padding: bool) -> Option<usize> {
+pub const fn encoded_len(bytes_len: usize, padding: bool) -> Option<usize> {
let rem = bytes_len % 3;
let complete_input_chunks = bytes_len / 3;
- let complete_chunk_output = complete_input_chunks.checked_mul(4);
+ // `let Some(_) = _ else` requires 1.65.0, whereas this messier one works on 1.48
+ let complete_chunk_output =
+ if let Some(complete_chunk_output) = complete_input_chunks.checked_mul(4) {
+ complete_chunk_output
+ } else {
+ return None;
+ };
if rem > 0 {
if padding {
- complete_chunk_output.and_then(|c| c.checked_add(4))
+ complete_chunk_output.checked_add(4)
} else {
let encoded_rem = match rem {
1 => 2,
- 2 => 3,
- _ => unreachable!("Impossible remainder"),
+ // only other possible remainder is 2
+ // can't use a separate _ => unreachable!() in const fns in ancient rust versions
+ _ => 3,
};
- complete_chunk_output.and_then(|c| c.checked_add(encoded_rem))
+ complete_chunk_output.checked_add(encoded_rem)
}
} else {
- complete_chunk_output
+ Some(complete_chunk_output)
}
}
diff --git a/vendor/base64/src/engine/general_purpose/mod.rs b/vendor/base64/src/engine/general_purpose/mod.rs
index 01d22049a..e0227f3b8 100644
--- a/vendor/base64/src/engine/general_purpose/mod.rs
+++ b/vendor/base64/src/engine/general_purpose/mod.rs
@@ -19,6 +19,8 @@ pub(crate) const INVALID_VALUE: u8 = 255;
/// - It uses no vector CPU instructions, so it will work on any system.
/// - It is reasonably fast (~2-3GiB/s).
/// - It is not constant-time, though, so it is vulnerable to timing side-channel attacks. For loading cryptographic keys, etc, it is suggested to use the forthcoming constant-time implementation.
+
+#[derive(Debug, Clone)]
pub struct GeneralPurpose {
encode_table: [u8; 64],
decode_table: [u8; 256],
diff --git a/vendor/base64/src/engine/mod.rs b/vendor/base64/src/engine/mod.rs
index e10d66bb2..16c05d751 100644
--- a/vendor/base64/src/engine/mod.rs
+++ b/vendor/base64/src/engine/mod.rs
@@ -1,14 +1,14 @@
//! Provides the [Engine] abstraction and out of the box implementations.
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use crate::chunked_encoder;
use crate::{
encode::{encode_with_padding, EncodeSliceError},
encoded_len, DecodeError, DecodeSliceError,
};
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use alloc::vec::Vec;
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
use alloc::{string::String, vec};
pub mod general_purpose;
@@ -113,7 +113,7 @@ pub trait Engine: Send + Sync {
/// engine::GeneralPurpose::new(&alphabet::URL_SAFE, general_purpose::NO_PAD);
///
/// let b64_url = CUSTOM_ENGINE.encode(b"hello internet~");
- #[cfg(any(feature = "alloc", feature = "std", test))]
+ #[cfg(any(feature = "alloc", test))]
#[inline]
fn encode<T: AsRef<[u8]>>(&self, input: T) -> String {
fn inner<E>(engine: &E, input_bytes: &[u8]) -> String
@@ -153,7 +153,7 @@ pub trait Engine: Send + Sync {
/// println!("{}", buf);
/// }
/// ```
- #[cfg(any(feature = "alloc", feature = "std", test))]
+ #[cfg(any(feature = "alloc", test))]
#[inline]
fn encode_string<T: AsRef<[u8]>>(&self, input: T, output_buf: &mut String) {
fn inner<E>(engine: &E, input_bytes: &[u8], output_buf: &mut String)
@@ -178,7 +178,8 @@ pub trait Engine: Send + Sync {
///
/// # Example
///
- /// ```rust
+ #[cfg_attr(feature = "alloc", doc = "```")]
+ #[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use base64::{Engine as _, engine::general_purpose};
/// let s = b"hello internet!";
/// let mut buf = Vec::new();
@@ -241,7 +242,7 @@ pub trait Engine: Send + Sync {
/// .decode("aGVsbG8gaW50ZXJuZXR-Cg").unwrap();
/// println!("{:?}", bytes_url);
/// ```
- #[cfg(any(feature = "alloc", feature = "std", test))]
+ #[cfg(any(feature = "alloc", test))]
#[inline]
fn decode<T: AsRef<[u8]>>(&self, input: T) -> Result<Vec<u8>, DecodeError> {
fn inner<E>(engine: &E, input_bytes: &[u8]) -> Result<Vec<u8>, DecodeError>
@@ -293,7 +294,7 @@ pub trait Engine: Send + Sync {
/// println!("{:?}", buffer);
/// }
/// ```
- #[cfg(any(feature = "alloc", feature = "std", test))]
+ #[cfg(any(feature = "alloc", test))]
#[inline]
fn decode_vec<T: AsRef<[u8]>>(
&self,
diff --git a/vendor/base64/src/engine/naive.rs b/vendor/base64/src/engine/naive.rs
index 42b6085bd..6a50cbed9 100644
--- a/vendor/base64/src/engine/naive.rs
+++ b/vendor/base64/src/engine/naive.rs
@@ -6,8 +6,7 @@ use crate::{
},
DecodeError, PAD_BYTE,
};
-use alloc::ops::BitOr;
-use std::ops::{BitAnd, Shl, Shr};
+use std::ops::{BitAnd, BitOr, Shl, Shr};
/// Comparatively simple implementation that can be used as something to compare against in tests
pub struct Naive {
diff --git a/vendor/base64/src/lib.rs b/vendor/base64/src/lib.rs
index cc9d628df..6b11fa66b 100644
--- a/vendor/base64/src/lib.rs
+++ b/vendor/base64/src/lib.rs
@@ -81,7 +81,8 @@
//!
//! ## Using predefined engines
//!
-//! ```
+#![cfg_attr(feature = "alloc", doc = "```")]
+#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! use base64::{Engine as _, engine::general_purpose};
//!
//! let orig = b"data";
@@ -95,7 +96,8 @@
//!
//! ## Custom alphabet, config, and engine
//!
-//! ```
+#![cfg_attr(feature = "alloc", doc = "```")]
+#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! use base64::{engine, alphabet, Engine as _};
//!
//! // bizarro-world base64: +/ as the first symbols instead of the last
@@ -136,10 +138,8 @@
#![allow(clippy::single_component_path_imports)]
#![cfg_attr(not(any(feature = "std", test)), no_std)]
-#[cfg(all(feature = "alloc", not(any(feature = "std", test))))]
+#[cfg(any(feature = "alloc", test))]
extern crate alloc;
-#[cfg(any(feature = "std", test))]
-extern crate std as alloc;
// has to be included at top level because of the way rstest_reuse defines its macros
#[cfg(test)]
@@ -159,14 +159,14 @@ pub mod alphabet;
mod encode;
#[allow(deprecated)]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub use crate::encode::{encode, encode_engine, encode_engine_string};
#[allow(deprecated)]
pub use crate::encode::{encode_engine_slice, encoded_len, EncodeSliceError};
mod decode;
#[allow(deprecated)]
-#[cfg(any(feature = "alloc", feature = "std", test))]
+#[cfg(any(feature = "alloc", test))]
pub use crate::decode::{decode, decode_engine, decode_engine_vec};
#[allow(deprecated)]
pub use crate::decode::{decode_engine_slice, decoded_len_estimate, DecodeError, DecodeSliceError};
diff --git a/vendor/base64/src/prelude.rs b/vendor/base64/src/prelude.rs
index fbeb5babc..df5fdb497 100644
--- a/vendor/base64/src/prelude.rs
+++ b/vendor/base64/src/prelude.rs
@@ -5,7 +5,8 @@
//!
//! # Examples
//!
-//! ```
+#![cfg_attr(feature = "alloc", doc = "```")]
+#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD};
//!
//! assert_eq!("c29tZSBieXRlcw", &BASE64_STANDARD_NO_PAD.encode(b"some bytes"));
diff --git a/vendor/base64/src/read/decoder_tests.rs b/vendor/base64/src/read/decoder_tests.rs
index 625a07dbd..099dd6388 100644
--- a/vendor/base64/src/read/decoder_tests.rs
+++ b/vendor/base64/src/read/decoder_tests.rs
@@ -76,7 +76,7 @@ fn trailing_junk() {
saw_error = true;
break;
}
- Ok(read) if read == 0 => break,
+ Ok(0) => break,
Ok(_) => (),
}
}