Browse Source

update deps

pull/24/head
Sun 3 years ago
parent
commit
92c7192cbc
  1. 2
      Cargo.toml
  2. 9
      src/account.rs
  3. 10
      src/apps/dao/models/group.rs
  4. 10
      src/apps/file/models.rs
  5. 8
      src/apps/group/models/group.rs
  6. 9
      src/apps/jarvis/rpc.rs
  7. 14
      src/storage.rs

2
Cargo.toml

@ -44,7 +44,7 @@ blake3 = "1.3"
hex = "0.4" hex = "0.4"
image = "0.24" image = "0.24"
once_cell = "1.9" once_cell = "1.9"
rand = "0.8" rand_chacha = "0.3"
sha2 = "0.10" sha2 = "0.10"
sysinfo = "0.23" sysinfo = "0.23"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }

9
src/account.rs

@ -1,4 +1,7 @@
use rand::Rng; use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{ use tdn::types::{
@ -145,7 +148,9 @@ impl Account {
let wallet = ChainToken::ETH.update_main(&wallet_address, ""); let wallet = ChainToken::ETH.update_main(&wallet_address, "");
let w = Address::new(ChainToken::ETH, 0, wallet_address, true); 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 ckey = encrypt_key(salt, lock, &key)?;
let mut ebytes = encrypt_multiple( let mut ebytes = encrypt_multiple(
salt, salt,

10
src/apps/dao/models/group.rs

@ -1,4 +1,7 @@
use rand::Rng; use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::path::PathBuf; use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{ use tdn::types::{
@ -58,7 +61,10 @@ impl GroupChat {
is_ok: bool, is_ok: bool,
is_remote: bool, is_remote: bool,
) -> Self { ) -> 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 start = SystemTime::now();
let datetime = start let datetime = start

10
src/apps/file/models.rs

@ -1,4 +1,7 @@
use rand::Rng; use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{ use tdn::types::{
@ -50,7 +53,10 @@ pub(crate) struct FileDid([u8; 32]);
impl FileDid { impl FileDid {
pub fn generate() -> Self { 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 { pub fn to_hex(&self) -> String {

8
src/apps/group/models/group.rs

@ -1,5 +1,8 @@
use group_types::GroupChatId; use group_types::GroupChatId;
use rand::Rng; use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::{ use tdn::types::{
primitives::{PeerId, Result}, primitives::{PeerId, Result},
@ -31,7 +34,8 @@ pub(crate) struct GroupChat {
impl GroupChat { impl GroupChat {
pub fn new(addr: PeerId, name: String) -> Self { 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 { Self {
gid, gid,

9
src/apps/jarvis/rpc.rs

@ -1,5 +1,8 @@
use esse_primitives::MessageType; use esse_primitives::MessageType;
use rand::Rng; use rand_chacha::{
rand_core::{RngCore, SeedableRng},
ChaChaRng,
};
use std::sync::Arc; use std::sync::Arc;
use tdn::types::{ use tdn::types::{
message::RpcSendMessage, message::RpcSendMessage,
@ -28,7 +31,9 @@ async fn reply(
let content = if msg.m_type == MessageType::String { let content = if msg.m_type == MessageType::String {
if msg.content.ends_with("?") || msg.content.ends_with("?") { if msg.content.ends_with("?") || msg.content.ends_with("?") {
// answer book. ascill ? and SBC case. // 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) load_answer(&lang, answer)
} else { } else {
msg.content msg.content

14
src/storage.rs

@ -1,6 +1,9 @@
use esse_primitives::id_to_str; use esse_primitives::id_to_str;
use image::{load_from_memory, DynamicImage, GenericImageView}; 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::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use tdn::types::primitives::{PeerId, Result}; use tdn::types::primitives::{PeerId, Result};
@ -127,11 +130,10 @@ pub(crate) async fn read_image(base: &PathBuf, pid: &PeerId, name: &str) -> Resu
#[inline] #[inline]
fn image_name() -> String { fn image_name() -> String {
let mut name: String = thread_rng() let mut rng = ChaChaRng::from_entropy();
.sample_iter(&Alphanumeric) let mut key = [0u8; 20];
.take(20) rng.fill_bytes(&mut key);
.map(char::from) let mut name = hex::encode(&key);
.collect();
name.push_str(".png"); name.push_str(".png");
name name
} }

Loading…
Cancel
Save