1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#![forbid(unsafe_code)]

use crate::error::S3Error;
use base64::engine::general_purpose;
use base64::Engine;
use std::env;

pub use reqwest::Response as S3Response;
pub use reqwest::StatusCode as S3StatusCode;

mod bucket;
mod command;
mod constants;
mod credentials;
mod error;
pub mod prelude;
mod signature;
mod types;

#[derive(Debug, Clone)]
pub struct Region(String);

impl Region {
    pub fn try_from_env() -> Result<Self, S3Error> {
        Ok(Self(env::var("S3_REGION")?))
    }

    pub fn as_str(&self) -> &str {
        self.0.as_str()
    }
}

fn md5_url_encode(s: &[u8]) -> String {
    general_purpose::STANDARD.encode(md5::compute(s).as_ref())
}