Unverified Commit e31c6aef authored by Nugine's avatar Nugine Committed by GitHub
Browse files

fix(s3s::auth::secret_key): zeroize on drop (#36)

* fix(s3s::auth::secret_key): zeroize on drop

* track future size
parent 4df91501
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -3,23 +3,29 @@ use std::fmt;
use zeroize::Zeroize;

#[derive(Clone, PartialEq, Eq)]
pub struct SecretKey(String);

impl Zeroize for SecretKey {
    fn zeroize(&mut self) {
        self.0.zeroize();
    }
}
pub struct SecretKey(Box<str>);

impl SecretKey {
    #[inline(always)]
    fn new(s: String) -> Self {
        Self(s)
    fn new(s: impl Into<Box<str>>) -> Self {
        Self(s.into())
    }

    #[must_use]
    pub fn expose(&self) -> &str {
        self.0.as_str()
        &self.0
    }
}

impl Zeroize for SecretKey {
    fn zeroize(&mut self) {
        self.0.zeroize();
    }
}

impl Drop for SecretKey {
    fn drop(&mut self) {
        self.zeroize();
    }
}

@@ -31,13 +37,13 @@ impl From<String> for SecretKey {

impl From<Box<str>> for SecretKey {
    fn from(value: Box<str>) -> Self {
        Self::new(value.into())
        Self::new(value)
    }
}

impl From<&str> for SecretKey {
    fn from(value: &str) -> Self {
        Self::new(value.into())
        Self::new(value)
    }
}

+6 −6
Original line number Diff line number Diff line
@@ -705,17 +705,17 @@ mod tests {

        #[rustfmt::skip]
        let sizes = [
            future_size!(S3Service::call,                           2616),
            future_size!(call,                                      1432),
            future_size!(prepare,                                   1360),
            future_size!(SignatureContext::check,                   752),
            future_size!(S3Service::call,                           2600),
            future_size!(call,                                      1424),
            future_size!(prepare,                                   1352),
            future_size!(SignatureContext::check,                   744),
            future_size!(SignatureContext::v2_check,                280),
            future_size!(SignatureContext::v2_check_presigned_url,  184),
            future_size!(SignatureContext::v2_check_header_auth,    184),
            future_size!(SignatureContext::v4_check,                728),
            future_size!(SignatureContext::v4_check,                720),
            future_size!(SignatureContext::v4_check_post_signature, 368),
            future_size!(SignatureContext::v4_check_presigned_url,  456),
            future_size!(SignatureContext::v4_check_header_auth,    632),
            future_size!(SignatureContext::v4_check_header_auth,    624),
        ];

        println!("{:#?}", sizes);