Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teos-common: Fixes cryptography tests utils #245

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions teos-common/src/cryptography.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,13 @@ pub fn decrypt(encrypted_blob: &[u8], secret: &Txid) -> Result<Transaction, Decr
pub fn get_random_bytes(size: usize) -> Vec<u8> {
let mut rng = rand::thread_rng();
let uniform_u8 = Uniform::new(u8::MIN, u8::MAX);
let v: Vec<u8> = (&mut rng).sample_iter(uniform_u8).take(size).collect();

v
(&mut rng).sample_iter(uniform_u8).take(size).collect()
}

/// Gets a key pair generated in a pseudorandom way.
pub fn get_random_keypair() -> (SecretKey, PublicKey) {
let raw_sk = get_random_bytes(32);

loop {
if let Ok(sk) = SecretKey::from_slice(&raw_sk) {
if let Ok(sk) = SecretKey::from_slice(&get_random_bytes(32)) {
return (sk, PublicKey::from_secret_key(&Secp256k1::new(), &sk));
}
}
Expand Down