mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-03-25 19:53:07 +00:00
fix tests
This commit is contained in:
parent
7572188ab0
commit
74d8fd54d9
@ -1,4 +1,4 @@
|
|||||||
use aes_gcm::{aead::Aead, AeadCore, Aes256Gcm, Key, KeyInit};
|
use aes_gcm::{aead::Aead, AeadCore, Aes256Gcm, KeyInit};
|
||||||
use elliptic_curve::point::AffineCoordinates;
|
use elliptic_curve::point::AffineCoordinates;
|
||||||
use elliptic_curve::PrimeField;
|
use elliptic_curve::PrimeField;
|
||||||
use k256::{AffinePoint, FieldBytes, Scalar};
|
use k256::{AffinePoint, FieldBytes, Scalar};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use aes_gcm::{aead::Aead, Aes256Gcm, Key, KeyInit};
|
use aes_gcm::{aead::Aead, Aes256Gcm, KeyInit};
|
||||||
use common::merkle_tree_public::TreeHashType;
|
use common::merkle_tree_public::TreeHashType;
|
||||||
use constants_types::{CipherText, Nonce};
|
use constants_types::{CipherText, Nonce};
|
||||||
use elliptic_curve::point::AffineCoordinates;
|
use elliptic_curve::point::AffineCoordinates;
|
||||||
@ -102,17 +102,15 @@ impl AddressKeyHolder {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
use aes_gcm::{
|
use aes_gcm::{
|
||||||
aead::{Aead, KeyInit, OsRng},
|
aead::{Aead, KeyInit, OsRng},
|
||||||
Aes256Gcm,
|
Aes256Gcm,
|
||||||
};
|
};
|
||||||
use constants_types::{CipherText, Nonce};
|
use constants_types::{CipherText, Nonce};
|
||||||
use constants_types::{NULLIFIER_SECRET_CONST, VIEWING_SECRET_CONST};
|
use constants_types::{NULLIFIER_SECRET_CONST, VIEWING_SECRET_CONST};
|
||||||
|
use elliptic_curve::ff::Field;
|
||||||
use elliptic_curve::group::prime::PrimeCurveAffine;
|
use elliptic_curve::group::prime::PrimeCurveAffine;
|
||||||
use elliptic_curve::point::AffineCoordinates;
|
use elliptic_curve::point::AffineCoordinates;
|
||||||
use elliptic_curve::{ff::Field, PrimeField};
|
|
||||||
use k256::{AffinePoint, ProjectivePoint, Scalar};
|
use k256::{AffinePoint, ProjectivePoint, Scalar};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -137,7 +135,7 @@ mod tests {
|
|||||||
|
|
||||||
// Generate a random ephemeral public key sender
|
// Generate a random ephemeral public key sender
|
||||||
let scalar = Scalar::random(&mut OsRng);
|
let scalar = Scalar::random(&mut OsRng);
|
||||||
let ephemeral_public_key_sender = (ProjectivePoint::GENERATOR * scalar).to_affine();
|
let ephemeral_public_key_sender = (ProjectivePoint::generator() * scalar).to_affine();
|
||||||
|
|
||||||
// Calculate shared secret
|
// Calculate shared secret
|
||||||
let shared_secret =
|
let shared_secret =
|
||||||
@ -219,15 +217,8 @@ mod tests {
|
|||||||
let shared_secret =
|
let shared_secret =
|
||||||
address_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender);
|
address_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender);
|
||||||
|
|
||||||
// Prepare the encryption key from shared secret
|
|
||||||
let key_raw = serde_json::to_vec(&shared_secret).unwrap();
|
|
||||||
let key_raw_adjust_pre = &key_raw.as_slice()[..32];
|
|
||||||
let key_raw_adjust: [u8; 32] = key_raw_adjust_pre.try_into().unwrap();
|
|
||||||
let key: Key<Aes256Gcm> = key_raw_adjust.into();
|
|
||||||
|
|
||||||
let cipher = Aes256Gcm::new(&key);
|
|
||||||
|
|
||||||
// Encrypt sample data with a specific nonce
|
// Encrypt sample data with a specific nonce
|
||||||
|
let cipher = Aes256Gcm::new(&shared_secret.x());
|
||||||
let nonce = Nonce::from_slice(b"unique nonce");
|
let nonce = Nonce::from_slice(b"unique nonce");
|
||||||
let plaintext = b"Sensitive data";
|
let plaintext = b"Sensitive data";
|
||||||
let ciphertext = cipher
|
let ciphertext = cipher
|
||||||
@ -259,15 +250,8 @@ mod tests {
|
|||||||
let shared_secret =
|
let shared_secret =
|
||||||
address_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender);
|
address_key_holder.calculate_shared_secret_receiver(ephemeral_public_key_sender);
|
||||||
|
|
||||||
// Prepare the encryption key from shared secret
|
|
||||||
let key_raw = serde_json::to_vec(&shared_secret).unwrap();
|
|
||||||
let key_raw_adjust_pre = &key_raw.as_slice()[..32];
|
|
||||||
let key_raw_adjust: [u8; 32] = key_raw_adjust_pre.try_into().unwrap();
|
|
||||||
let key: Key<Aes256Gcm> = key_raw_adjust.into();
|
|
||||||
|
|
||||||
let cipher = Aes256Gcm::new(&key);
|
|
||||||
|
|
||||||
// Encrypt sample data
|
// Encrypt sample data
|
||||||
|
let cipher = Aes256Gcm::new(&shared_secret.x());
|
||||||
let nonce = Nonce::from_slice(b"unique nonce");
|
let nonce = Nonce::from_slice(b"unique nonce");
|
||||||
let plaintext = b"Sensitive data";
|
let plaintext = b"Sensitive data";
|
||||||
let ciphertext = cipher
|
let ciphertext = cipher
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user