Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhuachuang committed Apr 20, 2022
1 parent 956bd06 commit 92c7192
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ blake3 = "1.3"
hex = "0.4"
image = "0.24"
once_cell = "1.9"
rand = "0.8"
rand_chacha = "0.3"
sha2 = "0.10"
sysinfo = "0.23"
serde = { version = "1", features = ["derive"] }
Expand Down
9 changes: 7 additions & 2 deletions src/account.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use rand::Rng;
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{
Expand Down Expand Up @@ -145,7 +148,9 @@ impl Account {
let wallet = ChainToken::ETH.update_main(&wallet_address, "");
let w = Address::new(ChainToken::ETH, 0, wallet_address, true);

let key = rand::thread_rng().gen::<[u8; 32]>();
let mut rng = ChaChaRng::from_entropy();
let mut key = [0u8; 32];
rng.fill_bytes(&mut key);
let ckey = encrypt_key(salt, lock, &key)?;
let mut ebytes = encrypt_multiple(
salt,
Expand Down
10 changes: 8 additions & 2 deletions src/apps/dao/models/group.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use rand::Rng;
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{
Expand Down Expand Up @@ -58,7 +61,10 @@ impl GroupChat {
is_ok: bool,
is_remote: bool,
) -> Self {
let g_id = GroupId(rand::thread_rng().gen::<[u8; 32]>());
let mut rng = ChaChaRng::from_entropy();
let mut bytes = [0u8; 32];
rng.fill_bytes(&mut bytes);
let g_id = GroupId(bytes);

let start = SystemTime::now();
let datetime = start
Expand Down
10 changes: 8 additions & 2 deletions src/apps/file/models.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use rand::Rng;
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{
Expand Down Expand Up @@ -50,7 +53,10 @@ pub(crate) struct FileDid([u8; 32]);

impl FileDid {
pub fn generate() -> Self {
Self(rand::thread_rng().gen::<[u8; 32]>())
let mut rng = ChaChaRng::from_entropy();
let mut key = [0u8; 32];
rng.fill_bytes(&mut key);
Self(key)
}

pub fn to_hex(&self) -> String {
Expand Down
8 changes: 6 additions & 2 deletions src/apps/group/models/group.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use group_types::GroupChatId;
use rand::Rng;
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{
primitives::{PeerId, Result},
Expand Down Expand Up @@ -31,7 +34,8 @@ pub(crate) struct GroupChat {

impl GroupChat {
pub fn new(addr: PeerId, name: String) -> Self {
let gid = rand::thread_rng().gen::<GroupChatId>();
let mut rng = ChaChaRng::from_entropy();
let gid = rng.next_u64();

Self {
gid,
Expand Down
9 changes: 7 additions & 2 deletions src/apps/jarvis/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use esse_primitives::MessageType;
use rand::Rng;
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::sync::Arc;
use tdn::types::{
message::RpcSendMessage,
Expand Down Expand Up @@ -28,7 +31,9 @@ async fn reply(
let content = if msg.m_type == MessageType::String {
if msg.content.ends_with("?") || msg.content.ends_with("?") {
// answer book. ascill ? and SBC case.
let answer = rand::thread_rng().gen_range(0..171);
let mut rng = ChaChaRng::from_entropy();
let n = rng.next_u32();
let answer = (n % 171) as usize;
load_answer(&lang, answer)
} else {
msg.content
Expand Down
14 changes: 8 additions & 6 deletions src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use esse_primitives::id_to_str;
use image::{load_from_memory, DynamicImage, GenericImageView};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::primitives::{PeerId, Result};
Expand Down Expand Up @@ -127,11 +130,10 @@ pub(crate) async fn read_image(base: &PathBuf, pid: &PeerId, name: &str) -> Resu

#[inline]
fn image_name() -> String {
let mut name: String = thread_rng()
.sample_iter(&Alphanumeric)
.take(20)
.map(char::from)
.collect();
let mut rng = ChaChaRng::from_entropy();
let mut key = [0u8; 20];
rng.fill_bytes(&mut key);
let mut name = hex::encode(&key);
name.push_str(".png");
name
}
Expand Down

0 comments on commit 92c7192

Please sign in to comment.