Update bincode to v2.0.0-rc3 (#109)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Prepare for the next major update of bincode Reviewed-on: #109
This commit is contained in:
@ -4,9 +4,8 @@ use aes_gcm::aead::{Aead, OsRng};
|
||||
use aes_gcm::{Aes256Gcm, Key, KeyInit, Nonce};
|
||||
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;
|
||||
use base64::Engine as _;
|
||||
use bincode::{Decode, Encode};
|
||||
use rand::Rng;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::utils::err::Res;
|
||||
|
||||
@ -25,11 +24,11 @@ impl CryptoWrapper {
|
||||
}
|
||||
|
||||
/// Encrypt some data
|
||||
pub fn encrypt<T: Serialize + DeserializeOwned>(&self, data: &T) -> Res<String> {
|
||||
pub fn encrypt<T: Encode + Decode>(&self, data: &T) -> Res<String> {
|
||||
let aes_key = Aes256Gcm::new(&self.key);
|
||||
let nonce_bytes = rand::thread_rng().gen::<[u8; NONCE_LEN]>();
|
||||
|
||||
let serialized_data = bincode::serialize(data)?;
|
||||
let serialized_data = bincode::encode_to_vec(data, bincode::config::standard())?;
|
||||
|
||||
let mut enc = aes_key
|
||||
.encrypt(Nonce::from_slice(&nonce_bytes), serialized_data.as_slice())
|
||||
@ -40,7 +39,7 @@ impl CryptoWrapper {
|
||||
}
|
||||
|
||||
/// Decrypt some data previously encrypted using the [`CryptoWrapper::encrypt`] method
|
||||
pub fn decrypt<T: DeserializeOwned>(&self, input: &str) -> Res<T> {
|
||||
pub fn decrypt<T: Decode>(&self, input: &str) -> Res<T> {
|
||||
let bytes = BASE64_STANDARD.decode(input)?;
|
||||
|
||||
if bytes.len() < NONCE_LEN {
|
||||
@ -66,15 +65,16 @@ impl CryptoWrapper {
|
||||
}
|
||||
};
|
||||
|
||||
Ok(bincode::deserialize(&dec)?)
|
||||
Ok(bincode::decode_from_slice(&dec, bincode::config::standard())?.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::data::crypto_wrapper::CryptoWrapper;
|
||||
use bincode::{Decode, Encode};
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Eq, PartialEq, Debug)]
|
||||
#[derive(Encode, Decode, Eq, PartialEq, Debug)]
|
||||
struct Message(String);
|
||||
|
||||
#[test]
|
||||
|
@ -1,3 +1,4 @@
|
||||
use bincode::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use std::net::IpAddr;
|
||||
|
||||
@ -10,7 +11,7 @@ use crate::data::totp_key::TotpKey;
|
||||
use crate::data::webauthn_manager::WebauthnPubKey;
|
||||
use crate::utils::time::{fmt_time, time};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Encode, Decode)]
|
||||
pub struct UserID(pub String);
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -2,6 +2,7 @@ use std::io::ErrorKind;
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web;
|
||||
use bincode::{Decode, Encode};
|
||||
use uuid::Uuid;
|
||||
use webauthn_rs::prelude::{
|
||||
CreationChallengeResponse, Passkey, PublicKeyCredential, RegisterPublicKeyCredential,
|
||||
@ -28,7 +29,7 @@ pub struct RegisterKeyRequest {
|
||||
pub creation_challenge: CreationChallengeResponse,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize, Encode, Decode)]
|
||||
struct RegisterKeyOpaqueData {
|
||||
registration_state: String,
|
||||
user_id: UserID,
|
||||
@ -40,7 +41,7 @@ pub struct AuthRequest {
|
||||
pub login_challenge: RequestChallengeResponse,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Encode, Decode)]
|
||||
struct AuthStateOpaqueData {
|
||||
authentication_state: String,
|
||||
user_id: UserID,
|
||||
|
Reference in New Issue
Block a user