feat: update base64 version

This commit is contained in:
2023-08-26 12:02:45 +08:00
parent 2ada122834
commit 1698e2d9f8
12 changed files with 47 additions and 24 deletions

View File

@@ -4,12 +4,14 @@ use std::thread;
use std::time::SystemTime;
use authenticator::{RegisterResult, StatusUpdate};
use base64::URL_SAFE_NO_PAD;
use base64::Engine;
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
use rand::Rng;
use rust_util::XResult;
use serde::{Deserialize, Serialize};
use crate::pkiutil::bytes_to_pem;
use crate::util::base64_encode;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct U2FDeviceInfo {
@@ -76,7 +78,7 @@ impl U2fRegistrationData {
device_info: U2FDeviceInfo::from(register_result),
device_name: registration.device_name,
client_data: client_data.into(),
registration_data: base64::encode(&register_result.0),
registration_data: base64_encode(&register_result.0),
attestation_cert: registration.attestation_cert.clone(),
attestation_cert_pem: registration.attestation_cert.map(|cert| {
bytes_to_pem("CERTIFICATE", cert)
@@ -101,7 +103,7 @@ impl U2fV2Challenge {
None => U2fV2Challenge::new_random(app_id, with_time_stamp_prefix),
Some(challenge_hex) => {
let challenge_bytes = opt_result!(hex::decode(challenge_hex), "Decode challenge hex failed: {}");
let challenge = base64::encode_config(&challenge_bytes, base64::URL_SAFE_NO_PAD);
let challenge = URL_SAFE_NO_PAD.encode(&challenge_bytes);
U2fV2Challenge::new(challenge, app_id)
}
})
@@ -120,7 +122,7 @@ impl U2fV2Challenge {
rand_bytes[..8].clone_from_slice(&timestamp_be_bytes[..8]);
}
let challenge = base64::encode_config(&rand_bytes, URL_SAFE_NO_PAD);
let challenge = URL_SAFE_NO_PAD.encode(&rand_bytes);
Self::new(challenge, app_id)
}