summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-07-17 17:32:54 +0200
committerpennae <github@quasiparticle.net>2022-07-17 17:32:54 +0200
commit3eda99e9efbdfc2cb0e20932f20018d53baf5a64 (patch)
tree058d266f4a193bd4de931f39bb115c7225376507
parent1ef9d67fb6979ea91812c4ea892f7ecc12b3170f (diff)
downloadminor-skulk-3eda99e9efbdfc2cb0e20932f20018d53baf5a64.tar.gz
minor-skulk-3eda99e9efbdfc2cb0e20932f20018d53baf5a64.tar.xz
minor-skulk-3eda99e9efbdfc2cb0e20932f20018d53baf5a64.zip
make the Clone bytes types Copy as well
u8 arrays are copy, no need to not have our wrappers be copy.
-rw-r--r--src/api/auth/account.rs18
-rw-r--r--src/api/auth/device.rs4
-rw-r--r--src/api/auth/mod.rs2
-rw-r--r--src/api/auth/oauth.rs7
-rw-r--r--src/api/profile/mod.rs3
-rw-r--r--src/crypto.rs8
-rw-r--r--src/db/mod.rs2
-rw-r--r--src/types.rs2
8 files changed, 18 insertions, 28 deletions
diff --git a/src/api/auth/account.rs b/src/api/auth/account.rs
index 9d2a19e..8f3ac55 100644
--- a/src/api/auth/account.rs
+++ b/src/api/auth/account.rs
@@ -100,10 +100,9 @@ pub(crate) async fn create(
let key_fetch_token = if keys {
let key_fetch_token = KeyFetchToken::generate();
let req = KeyFetchReq::derive_from(&key_fetch_token);
- let wrapped = req.derive_resp().wrap_keys(&KeyBundle {
- ka: ka.clone(),
- wrap_kb: stretched.decrypt_wwkb(&wrapwrap_kb),
- });
+ let wrapped = req
+ .derive_resp()
+ .wrap_keys(&KeyBundle { ka, wrap_kb: stretched.decrypt_wwkb(&wrapwrap_kb) });
db.add_key_fetch(req.token_id, &req.req_hmac_key, &wrapped).await?;
Some(key_fetch_token)
} else {
@@ -120,8 +119,7 @@ pub(crate) async fn create(
verified: false,
})
.await?;
- let auth_at =
- db.add_session(session.token_id.clone(), &uid, session.req_hmac_key, false, None).await?;
+ let auth_at = db.add_session(session.token_id, &uid, session.req_hmac_key, false, None).await?;
let verify_code = hex::encode(&random_bytes::<16>());
db.add_verify_code(&uid, &session.token_id, &verify_code).await?;
// NOTE we send the email in this context rather than a spawn to signal
@@ -215,13 +213,7 @@ pub(crate) async fn login(
let verify_code = format!("{:06}", thread_rng().gen_range(0..=999999));
let auth_at = db
- .add_session(
- session.token_id.clone(),
- &uid,
- session.req_hmac_key,
- false,
- Some(&verify_code),
- )
+ .add_session(session.token_id, &uid, session.req_hmac_key, false, Some(&verify_code))
.await?;
// NOTE we send the email in this context rather than a spawn to signal
// send errors to the client.
diff --git a/src/api/auth/device.rs b/src/api/auth/device.rs
index 2b05e12..44fbd2a 100644
--- a/src/api/auth/device.rs
+++ b/src/api/auth/device.rs
@@ -130,9 +130,9 @@ pub(crate) async fn device(
let (own_id, changed_id, notify) = match (dev.id, data.context.device_id) {
(None, None) => {
let new = DeviceID::random();
- (Some(new.clone()), new, true)
+ (Some(new), new, true)
},
- (None, Some(own)) => (Some(own.clone()), own, false),
+ (None, Some(own)) => (Some(own), own, false),
(Some(other), own) => (own, other, false),
};
let result = db
diff --git a/src/api/auth/mod.rs b/src/api/auth/mod.rs
index a2a94e0..5c4f973 100644
--- a/src/api/auth/mod.rs
+++ b/src/api/auth/mod.rs
@@ -142,7 +142,7 @@ impl crate::auth::AuthSource for WithFxaLogin {
async fn hawk(r: &Request<'_>, id: &SessionID) -> anyhow::Result<(HawkKey, Self::Context)> {
let db = Authenticated::<(), Self>::get_conn(r).await?;
let k = db.use_session(id).await?;
- Ok((k.req_hmac_key.clone(), k))
+ Ok((k.req_hmac_key, k))
}
async fn bearer_token(
_: &Request<'_>,
diff --git a/src/api/auth/oauth.rs b/src/api/auth/oauth.rs
index 28d9fb2..384d4b4 100644
--- a/src/api/auth/oauth.rs
+++ b/src/api/auth/oauth.rs
@@ -304,7 +304,7 @@ pub(crate) async fn token_authenticated(
Some(req.context.created_at),
req.body,
None,
- Some(req.session.clone()),
+ Some(req.session),
)
.await
}
@@ -380,7 +380,7 @@ async fn token_impl(
db.add_access_token(
&access_token.hash(),
OauthAccessToken {
- user_id: user_id.clone(),
+ user_id,
client_id: req.client_id.clone(),
scope: scope.clone(),
parent_refresh,
@@ -394,8 +394,7 @@ async fn token_impl(
let (session_token, session_id) = if scope.implies(&SESSION_SCOPE) {
let session_token = SessionToken::generate();
let session = SessionCredentials::derive_from(&session_token);
- db.add_session(session.token_id.clone(), &user_id, session.req_hmac_key, true, None)
- .await?;
+ db.add_session(session.token_id, &user_id, session.req_hmac_key, true, None).await?;
(Some(session_token), Some(session.token_id))
} else {
(None, None)
diff --git a/src/api/profile/mod.rs b/src/api/profile/mod.rs
index 9abb872..ecfec12 100644
--- a/src/api/profile/mod.rs
+++ b/src/api/profile/mod.rs
@@ -290,8 +290,7 @@ pub(crate) async fn avatar_upload(
sha.update(&data);
let id = AvatarID(sha.finalize()[0..16].try_into().unwrap());
- db.set_user_avatar(&req.session, Avatar { id: id.clone(), data, content_type: ct.to_string() })
- .await?;
+ db.set_user_avatar(&req.session, Avatar { id, data, content_type: ct.to_string() }).await?;
match db.get_devices(&req.session).await {
Ok(devs) => defer.spawn_after_success("api::profile/avatar/upload(post)", {
let (pc, db) = (Arc::clone(pc), db_pool.clone());
diff --git a/src/crypto.rs b/src/crypto.rs
index 58ab6d2..a188f46 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -111,7 +111,7 @@ impl StretchedPW {
}
}
-#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct SessionToken(#[serde(with = "as_hex")] [u8; 32]);
impl Debug for SessionToken {
@@ -138,7 +138,7 @@ impl SessionCredentials {
}
}
-#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct KeyFetchToken(#[serde(with = "as_hex")] [u8; 32]);
impl Debug for KeyFetchToken {
@@ -222,7 +222,7 @@ impl WrappedKeyBundle {
}
}
-#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct PasswordChangeToken(#[serde(with = "as_hex")] [u8; 32]);
impl Debug for PasswordChangeToken {
@@ -254,7 +254,7 @@ impl PasswordChangeReq {
}
}
-#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
+#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) struct AccountResetToken(#[serde(with = "as_hex")] [u8; 32]);
impl Debug for AccountResetToken {
diff --git a/src/db/mod.rs b/src/db/mod.rs
index bceab43..6cea895 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -245,7 +245,7 @@ impl DbConn {
)
.map(|r| {
(
- r.session_id.clone(),
+ r.session_id,
UserSession {
uid: r.uid,
req_hmac_key: r.req_hmac_key,
diff --git a/src/types.rs b/src/types.rs
index 342deab..7699483 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -63,7 +63,7 @@ macro_rules! bytea_types {
$( $rest:tt )*
) => {
bytea_types!{
- #[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+ #[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(try_from = "String", into = "String")]
struct $name($inner) as $sql_name {
fn decode(v) -> _ { &v.0[..] }