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" @@ -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"] }

9
src/account.rs

@ -1,4 +1,7 @@ @@ -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::{
@ -145,7 +148,9 @@ impl Account { @@ -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,

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

@ -1,4 +1,7 @@ @@ -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::{
@ -58,7 +61,10 @@ impl GroupChat { @@ -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

10
src/apps/file/models.rs

@ -1,4 +1,7 @@ @@ -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::{
@ -50,7 +53,10 @@ pub(crate) struct FileDid([u8; 32]); @@ -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 {

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

@ -1,5 +1,8 @@ @@ -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},
@ -31,7 +34,8 @@ pub(crate) struct GroupChat { @@ -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,

9
src/apps/jarvis/rpc.rs

@ -1,5 +1,8 @@ @@ -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,
@ -28,7 +31,9 @@ async fn reply( @@ -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

14
src/storage.rs

@ -1,6 +1,9 @@ @@ -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};
@ -127,11 +130,10 @@ pub(crate) async fn read_image(base: &PathBuf, pid: &PeerId, name: &str) -> Resu @@ -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
}

Loading…
Cancel
Save