Skip to content

Commit

Permalink
chore: update rand from 0.8.5 to 0.9.0
Browse files Browse the repository at this point in the history
New rand crate changes
- sub module distributions renamed to distr
- api thread_rng renamed to rng
- OsRng now only supports TryRngCore (probably catch an error)

Signed-off-by: Xynnn007 <[email protected]>
  • Loading branch information
Xynnn007 committed Feb 11, 2025
1 parent fd05e8e commit acfcc60
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ nix = "0.29"
openssl = "0.10"
prost = "0.13"
protobuf = "3.5.1"
rand = "0.8.5"
rand = "0.9.0"
reqwest = { version = "0.12", default-features = false }
resource_uri = { path = "attestation-agent/deps/resource_uri" }
ring = "0.17"
Expand Down
8 changes: 4 additions & 4 deletions attestation-agent/coco_keyprovider/src/enc_mods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anyhow::*;
use base64::Engine;
use jwt_simple::prelude::Ed25519KeyPair;
use log::{debug, info};
use rand::RngCore;
use rand::TryRngCore;
use reqwest::Url;
use serde::{Deserialize, Serialize};
use tokio::fs;
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn generate_key_parameters(input_params: &InputParams) -> Result<(Vec<u8>,
debug!("use given key from: {kpath}");
let key = fs::read(kpath).await.context("read Key file failed")?;
let mut iv = [0; 12];
rand::rngs::OsRng.fill_bytes(&mut iv);
rand::rngs::OsRng.try_fill_bytes(&mut iv)?;
let kid = match &input_params.keyid {
Some(kid) => kid.to_string(),
None => {
Expand All @@ -129,10 +129,10 @@ async fn generate_key_parameters(input_params: &InputParams) -> Result<(Vec<u8>,
debug!("no key input, generate a random key");

let mut iv = [0; 12];
rand::rngs::OsRng.fill_bytes(&mut iv);
rand::rngs::OsRng.try_fill_bytes(&mut iv)?;

let mut key = [0; 32];
rand::rngs::OsRng.fill_bytes(&mut key);
rand::rngs::OsRng.try_fill_bytes(&mut key)?;

let kid = match &input_params.keyid {
Some(kid) => kid.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion attestation-agent/deps/crypto/src/rust/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct RSAKeyPair {

impl RSAKeyPair {
pub fn new() -> Result<RSAKeyPair> {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let private_key = RsaPrivateKey::new(&mut rng, RSA_PUBKEY_LENGTH)?;
let public_key = RsaPublicKey::from(&private_key);
Expand Down
4 changes: 2 additions & 2 deletions confidential-data-hub/hub/src/bin/secret_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ async fn seal_secret(seal_args: &SealArgs) {
let (mut encrypter, provider_settings, provider) =
handle_envelope_provider(&env.command).await;
let mut iv = [0u8; 12];
rand::thread_rng().fill(&mut iv);
rand::rng().fill(&mut iv);
let mut key = [0u8; 32];
rand::thread_rng().fill(&mut key);
rand::rng().fill(&mut key);
let encrypted_data = crypto::encrypt(
Zeroizing::new(key.to_vec()),
blob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use anyhow::bail;
use chrono::Utc;
use credential::StsCredential;
use log::error;
use rand::{distributions::Alphanumeric, Rng};
use rand::{distr::Alphanumeric, Rng};
use reqwest::{header::HeaderMap, ClientBuilder};
use serde::Deserialize;
use serde_json::Value;
Expand Down Expand Up @@ -194,10 +194,7 @@ impl StsTokenClient {
"SignatureVersion".to_string(),
Self::SIGNATURE_VERSION.to_string(),
);
let bytes: Vec<u8> = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(16)
.collect();
let bytes: Vec<u8> = rand::rng().sample_iter(&Alphanumeric).take(16).collect();
let hex_nonce: String = bytes.iter().fold(String::new(), |mut output, b| {
let _ = write!(output, "{b:02X}");
output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn create_random_secret() -> Vec<u8> {

let data_length = 10;

let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let data: Vec<u8> = (0..data_length)
.map(|_| rng.sample(Uniform::new_inclusive(0, 255)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{collections::HashMap, os::unix::fs::PermissionsExt};
use anyhow::Context;
use async_trait::async_trait;
use log::{debug, error};
use rand::{distributions::Alphanumeric, Rng};
use rand::{distr::Alphanumeric, Rng};
use serde::{Deserialize, Serialize};
use tokio::{
fs,
Expand Down Expand Up @@ -78,7 +78,7 @@ async fn get_plaintext_secret(secret: &str) -> anyhow::Result<String> {
async fn create_random_dir() -> anyhow::Result<String> {
const NAME_LENGTH: usize = 10;

let name: String = rand::thread_rng()
let name: String = rand::rng()
.sample_iter(&Alphanumeric)
.take(NAME_LENGTH)
.map(char::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::Interpreter;
use super::{get_plaintext_key, BlockDeviceError, BlockDeviceParameters, Result};
use async_trait::async_trait;
use log::error;
use rand::{distributions::Alphanumeric, Rng};
use rand::{distr::Alphanumeric, Rng};
use tokio::{
fs,
io::{AsyncReadExt, AsyncWriteExt},
Expand All @@ -18,7 +18,7 @@ const LUKS_ENCRYPT_STORAGE_BIN: &str = "/usr/local/bin/luks-encrypt-storage";

async fn random_encrypt_key() -> Vec<u8> {
let mut buffer = vec![0u8; 4096];
rand::thread_rng().fill(&mut buffer[..]);
rand::rng().fill(&mut buffer[..]);
buffer
}

Expand Down Expand Up @@ -47,7 +47,7 @@ impl Interpreter for LuksInterpreter {
parameters: BlockDeviceParameters,
mount_point: &str,
) -> Result<()> {
let random_string: String = rand::thread_rng()
let random_string: String = rand::rng()
.sample_iter(&Alphanumeric)
.take(5)
.map(char::from)
Expand Down

0 comments on commit acfcc60

Please sign in to comment.