diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/http-auth/src | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/http-auth/src')
-rw-r--r-- | vendor/http-auth/src/basic.rs | 5 | ||||
-rw-r--r-- | vendor/http-auth/src/lib.rs | 23 | ||||
-rw-r--r-- | vendor/http-auth/src/parser.rs | 2 | ||||
-rw-r--r-- | vendor/http-auth/src/table.rs | 135 |
4 files changed, 145 insertions, 20 deletions
diff --git a/vendor/http-auth/src/basic.rs b/vendor/http-auth/src/basic.rs index d8e94ab65..14873c8e3 100644 --- a/vendor/http-auth/src/basic.rs +++ b/vendor/http-auth/src/basic.rs @@ -28,11 +28,12 @@ use crate::ChallengeRef; /// "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", /// ); pub fn encode_credentials(username: &str, password: &str) -> String { + use base64::Engine as _; let user_pass = format!("{}:{}", username, password); const PREFIX: &str = "Basic "; let mut value = String::with_capacity(PREFIX.len() + base64_encoded_len(user_pass.len())); value.push_str(PREFIX); - base64::encode_config_buf(&user_pass[..], base64::STANDARD, &mut value); + base64::engine::general_purpose::STANDARD.encode_string(&user_pass[..], &mut value); value } @@ -53,7 +54,7 @@ pub struct BasicClient { impl BasicClient { pub fn realm(&self) -> &str { - &*self.realm + &self.realm } /// Responds to the challenge with the supplied parameters. diff --git a/vendor/http-auth/src/lib.rs b/vendor/http-auth/src/lib.rs index 13a657ebb..59f7f665f 100644 --- a/vendor/http-auth/src/lib.rs +++ b/vendor/http-auth/src/lib.rs @@ -85,6 +85,8 @@ pub mod basic; #[cfg_attr(docsrs, doc(cfg(feature = "digest-scheme")))] pub mod digest; +mod table; + pub use parser::ChallengeParser; #[cfg(feature = "basic-scheme")] @@ -95,21 +97,10 @@ pub use crate::basic::BasicClient; #[cfg_attr(docsrs, doc(cfg(feature = "digest-scheme")))] pub use crate::digest::DigestClient; -// Must match build.rs exactly. -const C_TCHAR: u8 = 1; -const C_QDTEXT: u8 = 2; -const C_ESCAPABLE: u8 = 4; -const C_OWS: u8 = 8; - -#[cfg_attr(not(feature = "digest-scheme"), allow(unused))] -const C_ATTR: u8 = 16; +use crate::table::{char_classes, C_ESCAPABLE, C_OWS, C_QDTEXT, C_TCHAR}; -/// Returns a bitmask of `C_*` values indicating character classes. -fn char_classes(b: u8) -> u8 { - // This table is built by build.rs. - const TABLE: &[u8; 128] = include_bytes!(concat!(env!("OUT_DIR"), "/char_class_table.bin")); - *TABLE.get(usize::from(b)).unwrap_or(&0) -} +#[cfg(feature = "digest-scheme")] +use crate::table::C_ATTR; /// Parsed challenge (scheme and body) using references to the original header value. /// Produced by [`crate::parser::ChallengeParser`]. @@ -160,9 +151,7 @@ struct ParamsPrinter<'i>(&'i [ChallengeParamRef<'i>]); impl<'i> std::fmt::Debug for ParamsPrinter<'i> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_map() - .entries(self.0.iter().map(|&(ref k, ref v)| (k, v))) - .finish() + f.debug_map().entries(self.0.iter().copied()).finish() } } diff --git a/vendor/http-auth/src/parser.rs b/vendor/http-auth/src/parser.rs index a6eedf5b0..4c3aad7b8 100644 --- a/vendor/http-auth/src/parser.rs +++ b/vendor/http-auth/src/parser.rs @@ -127,7 +127,7 @@ impl<'i> Display for Error<'i> { "{} at byte {}: {:?}", self.error, self.pos, - format!( + format_args!( "{}(HERE-->){}", &self.input[..self.pos], &self.input[self.pos..] diff --git a/vendor/http-auth/src/table.rs b/vendor/http-auth/src/table.rs new file mode 100644 index 000000000..64a05d8b4 --- /dev/null +++ b/vendor/http-auth/src/table.rs @@ -0,0 +1,135 @@ +// Copyright (C) 2021 Scott Lamb <slamb@slamb.org> +// SPDX-License-Identifier: MIT OR Apache-2.0 + +//! Builds and offers lookup on a table of byte values to the character +//! classes the respective bytes are part of. Most classes are referenced from +//! [RFC 7235 Appendix B: Imported ABNF](https://datatracker.ietf.org/doc/html/rfc7235#appendix-B) +//! or [RFC 7235 Appendix C: Collected ABNF](https://datatracker.ietf.org/doc/html/rfc7235#appendix-C). + +pub(crate) const C_TCHAR: u8 = 1; +pub(crate) const C_QDTEXT: u8 = 2; +pub(crate) const C_ESCAPABLE: u8 = 4; +pub(crate) const C_OWS: u8 = 8; +pub(crate) const C_ATTR: u8 = 16; + +static TABLE: [u8; 128] = build_table(); + +pub(crate) fn char_classes(b: u8) -> u8 { + *TABLE.get(usize::from(b)).unwrap_or(&0) +} + +const fn build_table() -> [u8; 128] { + // It'd be nice to use array::from_fn here, but it wasn't stablized until Rust 1.63. + let mut table = [0u8; 128]; + let mut i = 0; + while i < 128 { + let b = i as u8; + let mut classes = 0; + if is_tchar(b) { + classes |= C_TCHAR; + } + if is_qdtext(b) { + classes |= C_QDTEXT; + } + if is_escapable(b) { + classes |= C_ESCAPABLE; + } + if is_ows(b) { + classes |= C_OWS; + } + if is_attr(b) { + classes |= C_ATTR; + } + table[i] = classes; + i += 1; + } + table +} + +/// Returns if the byte is a `tchar` as defined in +/// [RFC 7230 section 3.2.6](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6). +const fn is_tchar(b: u8) -> bool { + // tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*" + // / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" + // / DIGIT / ALPHA + // ; any VCHAR, except delimiters + matches!(b, + b'!' + | b'#' + | b'$' + | b'%' + | b'&' + | b'\'' + | b'*' + | b'+' + | b'-' + | b'.' + | b'^' + | b'_' + | b'`' + | b'|' + | b'~' + | b'0'..=b'9' + | b'a'..=b'z' + | b'A'..=b'Z') +} + +/// Returns true if the byte is a valid `qdtext` (excluding `obs-text`), as defined in +/// [RFC 7230 section 3.2.6](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6). +/// +/// ```text +/// quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE +/// qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text +/// obs-text = %x80-FF +/// quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) +/// VCHAR = %x21-7E +/// ; visible (printing) characters +/// ``` +const fn is_qdtext(b: u8) -> bool { + matches!(b, b'\t' | b' ' | 0x21 | 0x23..=0x5B | 0x5D..=0x7E) +} + +/// Returns true if the byte is a valid end of a `quoted-pair`, as defined in +/// [RFC 7230 section 3.2.6](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6). +const fn is_escapable(b: u8) -> bool { + matches!(b, b'\t' | b' ' | 0x21..=0x7E | 0x80..=0xFF) +} + +/// Returns true if the byte is a valid `attr-char` as defined in +/// [RFC 5987 section 3.2.1](https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1). +/// +/// ```text +/// attr-char = ALPHA / DIGIT +/// / "!" / "#" / "$" / "&" / "+" / "-" / "." +/// / "^" / "_" / "`" / "|" / "~" +/// ; token except ( "*" / "'" / "%" ) +/// ``` +const fn is_attr(b: u8) -> bool { + matches!(b, + b'a'..=b'z' + | b'A'..=b'Z' + | b'0'..=b'9' + | b'!' + | b'#' + | b'$' + | b'&' + | b'+' + | b'-' + | b'.' + | b'^' + | b'_' + | b'`' + | b'|' + | b'~') +} + +/// Returns true if the byte is valid optional whitespace as in [RFC 7230 section +/// 3.2.3](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.3). +/// +/// ```text +/// OWS = *( SP / HTAB ) +/// ; optional whitespace +/// ``` +const fn is_ows(b: u8) -> bool { + matches!(b, b' ' | b'\t') +} |