Unverified Commit 6b343828 authored by Nugine's avatar Nugine
Browse files

s3s: use rust_utils

parent b26c32a0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
arrayvec = "0.7.2"
ascii = { version = "1.1.0", default-features = false }
async-trait = "0.1.68"
atoi = { version = "2.0.0", default-features = false }
base64-simd = "0.8.0"
@@ -32,6 +31,7 @@ hyper = { version = "0.14.26", features = ["stream"] }
memchr = "2.5.0"
mime = "0.3.17"
nom = "7.1.3"
nugine-rust-utils = { version = "0.1.2", features = ["ascii", "utf8"] }
pin-project-lite = "0.2.9"
quick-xml = { version = "0.28.2", features = ["serialize"] }
serde = { version = "1.0.160", features = ["derive"] }
+2 −2
Original line number Diff line number Diff line
//! HTTP Range header

use crate::http;
use crate::utils::from_ascii;
use crate::S3Error;
use crate::S3ErrorCode;

use std::ops;

use atoi::FromRadix10Checked;
use rust_utils::str_from_ascii;

/// HTTP Range header
///
@@ -145,7 +145,7 @@ impl http::TryFromHeaderValue for Range {
    type Error = ParseRangeError;

    fn try_from_header_value(val: &http::HeaderValue) -> Result<Self, Self::Error> {
        let header = from_ascii(val.as_bytes()).ok_or(ParseRangeError { _priv: () })?;
        let header = str_from_ascii(val.as_bytes()).ok_or(ParseRangeError { _priv: () })?;
        Self::parse(header)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -4,12 +4,12 @@ use crate::dto::{List, Metadata, StreamingBlob, Timestamp, TimestampFormat};
use crate::error::*;
use crate::http::{HeaderName, HeaderValue};
use crate::path::S3Path;
use crate::utils::from_utf8_vec;
use crate::xml;

use std::fmt;
use std::str::FromStr;

use rust_utils::string_from_utf8;
use tracing::debug;

fn missing_header(name: &HeaderName) -> S3Error {
@@ -188,7 +188,7 @@ where

pub fn take_string_body(req: &mut Request) -> S3Result<String> {
    let bytes = req.body.bytes().expect("full body not found");
    match from_utf8_vec(bytes.into()) {
    match string_from_utf8(bytes.into()) {
        Some(s) => Ok(s),
        None => Err(invalid_request!("expected UTF-8 body")),
    }
+2 −2
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ use super::AmzDate;

use crate::auth::SecretKey;
use crate::http::OrderedHeaders;
use crate::utils::from_ascii;
use crate::utils::hmac_sha256;
use crate::utils::stable_sort_by_first;

@@ -13,6 +12,7 @@ use std::mem::MaybeUninit;
use hex_simd::{AsOut, AsciiCase};
use hyper::body::Bytes;
use hyper::Method;
use rust_utils::str_from_ascii;
use sha2::{Digest, Sha256};
use smallvec::SmallVec;
use zeroize::Zeroize;
@@ -75,7 +75,7 @@ fn uri_encode(output: &mut String, input: &str, encode_slash: bool) {
        }
    }

    let s = from_ascii(buf.as_ref()).unwrap();
    let s = str_from_ascii(buf.as_ref()).unwrap();
    output.push_str(s);
}

+0 −11
Original line number Diff line number Diff line
@@ -6,17 +6,6 @@ use std::pin::Pin;

use arrayvec::{ArrayString, ArrayVec};

/// TODO(blocking): use `unicode_simd::from_ascii`
pub fn from_ascii(s: &[u8]) -> Option<&str> {
    ascii::AsciiStr::from_ascii(s).ok().map(ascii::AsciiStr::as_str)
}

/// TODO(blocking): SIMD
/// `https://github.com/rusticstuff/simdutf8/issues/73`
pub fn from_utf8_vec(v: Vec<u8>) -> Option<String> {
    String::from_utf8(v).ok()
}

/// on-stack formatting
pub const fn fmt_boolean(val: bool) -> &'static str {
    if val {
Loading