Update bincode to v2.0.0-rc.3
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2023-04-28 10:21:41 +02:00
parent eafa624aa0
commit ba89d4b3f1
5 changed files with 31 additions and 13 deletions

20
Cargo.lock generated
View File

@ -604,13 +604,23 @@ dependencies = [
[[package]]
name = "bincode"
version = "1.3.3"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95"
dependencies = [
"bincode_derive",
"serde",
]
[[package]]
name = "bincode_derive"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c"
dependencies = [
"virtue",
]
[[package]]
name = "binstring"
version = "0.1.1"
@ -2982,6 +2992,12 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "virtue"
version = "0.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
[[package]]
name = "want"
version = "0.3.0"

View File

@ -35,7 +35,7 @@ qrcode-generator = "4.1.8"
webauthn-rs = { version = "0.4.8", features = ["danger-allow-state-serialisation"] }
url = "2.3.1"
aes-gcm = { version = "0.10.1", features = ["aes"] }
bincode = "1.3.3"
bincode = "2.0.0-rc.3"
chrono = "0.4.24"
lazy_static = "1.4.0"
reqwest = { version = "0.11.16", features = ["json"] }

View File

@ -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]

View File

@ -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)]

View File

@ -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,