cargo fmt
This commit is contained in:
parent
70dc18ef97
commit
8dde96b93c
@ -1,10 +1,10 @@
|
|||||||
/* This module is temporary. We'll use the module described in key_encription
|
/* This module is temporary. We'll use the module described in key_encription
|
||||||
module defined in sdk_common repository! Some of the methods there were copied here.
|
module defined in sdk_common repository! Some of the methods there were copied here.
|
||||||
*/
|
*/
|
||||||
use wasm_bindgen::JsValue;
|
|
||||||
use web_sys::console;
|
|
||||||
use core::result::Result as CoreResult;
|
use core::result::Result as CoreResult;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
use wasm_bindgen::JsValue;
|
||||||
|
use web_sys::console;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
@ -15,16 +15,14 @@ use aes_gcm::{
|
|||||||
aead::{AeadInPlace, KeyInit},
|
aead::{AeadInPlace, KeyInit},
|
||||||
Aes256Gcm,
|
Aes256Gcm,
|
||||||
};
|
};
|
||||||
use rand::rngs::OsRng;
|
|
||||||
use hex;
|
use hex;
|
||||||
use hex::FromHexError;
|
use hex::FromHexError;
|
||||||
|
use rand::rngs::OsRng;
|
||||||
|
|
||||||
pub struct Aes256GcmIv96Bit {
|
pub struct Aes256GcmIv96Bit {
|
||||||
pub key: GenericArray<u8, U32>,
|
pub key: GenericArray<u8, U32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Aes256GcmIv96Bit {
|
impl Aes256GcmIv96Bit {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut key_bytes = [0u8; 32];
|
let mut key_bytes = [0u8; 32];
|
||||||
@ -96,7 +94,6 @@ impl Aes256GcmIv96Bit {
|
|||||||
Err(_) => Err("Échec du décodage de la clé".to_string()),
|
Err(_) => Err("Échec du décodage de la clé".to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
@ -120,7 +117,6 @@ impl KeyEncryption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode(&self, data: String) -> CoreResult<String, String> {
|
pub fn encode(&self, data: String) -> CoreResult<String, String> {
|
||||||
|
|
||||||
if let Some(ref key) = self.key {
|
if let Some(ref key) = self.key {
|
||||||
let decoded_key = Aes256GcmIv96Bit::import_key(key)?;
|
let decoded_key = Aes256GcmIv96Bit::import_key(key)?;
|
||||||
let encrypted_data = decoded_key.encrypt_string(&data)?;
|
let encrypted_data = decoded_key.encrypt_string(&data)?;
|
||||||
|
@ -11,6 +11,8 @@ use wasm_bindgen::convert::FromWasmAbi;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
use sp_backend::spclient::SpendKey;
|
use sp_backend::spclient::SpendKey;
|
||||||
|
use sp_backend::spclient::{derive_keys_from_seed, OutputList, SpClient};
|
||||||
|
|
||||||
type ApiResult<T: FromWasmAbi> = Result<T, ApiError>;
|
type ApiResult<T: FromWasmAbi> = Result<T, ApiError>;
|
||||||
|
|
||||||
const IS_TESTNET: bool = true;
|
const IS_TESTNET: bool = true;
|
||||||
|
@ -2,7 +2,8 @@ use wasm_bindgen::prelude::*;
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn inject_html_create_id() -> String {
|
pub fn inject_html_create_id() -> String {
|
||||||
String::from("
|
String::from(
|
||||||
|
"
|
||||||
<div class='card'>
|
<div class='card'>
|
||||||
<div class='side-by-side'>
|
<div class='side-by-side'>
|
||||||
<h3>Create an Id</h3>
|
<h3>Create an Id</h3>
|
||||||
@ -22,7 +23,8 @@ pub fn inject_html_create_id() -> String {
|
|||||||
</form><br/>
|
</form><br/>
|
||||||
<div id='passwordalert' class='passwordalert'></div>
|
<div id='passwordalert' class='passwordalert'></div>
|
||||||
</div>
|
</div>
|
||||||
")
|
",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
@ -75,7 +77,8 @@ pub fn inject_html_revokeimage() -> String {
|
|||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn inject_html_revoke() -> String {
|
pub fn inject_html_revoke() -> String {
|
||||||
String::from("
|
String::from(
|
||||||
|
"
|
||||||
<div class='card'>
|
<div class='card'>
|
||||||
<div class='side-by-side'>
|
<div class='side-by-side'>
|
||||||
<h3>Revoke an Id</h3>
|
<h3>Revoke an Id</h3>
|
||||||
@ -95,5 +98,6 @@ pub fn inject_html_revoke() -> String {
|
|||||||
<button type='submit' id='submitButton' class='recover bg-primary'>Revoke</button>
|
<button type='submit' id='submitButton' class='recover bg-primary'>Revoke</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
")
|
",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
|
mod aesgcm;
|
||||||
pub mod api;
|
pub mod api;
|
||||||
mod injecteurhtml;
|
mod injecteurhtml;
|
||||||
mod process;
|
mod process;
|
||||||
mod user;
|
|
||||||
mod aesgcm;
|
|
||||||
mod secretdata;
|
mod secretdata;
|
||||||
|
mod user;
|
||||||
|
@ -1,33 +1,31 @@
|
|||||||
|
use anyhow::Error;
|
||||||
use bitcoin::secp256k1::SecretKey;
|
use bitcoin::secp256k1::SecretKey;
|
||||||
|
use rand::{self, thread_rng, Rng, RngCore};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use rand::{self, Rng,thread_rng, RngCore};
|
use tsify::Tsify;
|
||||||
use wasm_bindgen::JsValue;
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::JsValue;
|
||||||
use web_sys::console;
|
use web_sys::console;
|
||||||
use anyhow::Error;
|
|
||||||
|
|
||||||
use crate::aesgcm::{Aes256GcmIv96Bit, KeyEncryption};
|
use crate::aesgcm::{Aes256GcmIv96Bit, KeyEncryption};
|
||||||
use crate::secretdata::SecretData;
|
use crate::secretdata::SecretData;
|
||||||
use hex;
|
|
||||||
use sha2::{Sha256, Digest};
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use hex;
|
||||||
|
use sha2::{Digest, Sha256};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
use crate::api::{generate_sp_wallet_return,generate_sp_wallet};
|
use crate::api::{generate_sp_wallet, generate_sp_wallet_return};
|
||||||
use sp_backend::spclient::SpendKey;
|
|
||||||
use sp_backend::spclient::{SpClient, OutputList};
|
|
||||||
use sp_backend::silentpayments::sending::SilentPaymentAddress;
|
use sp_backend::silentpayments::sending::SilentPaymentAddress;
|
||||||
|
use sp_backend::spclient::SpendKey;
|
||||||
|
use sp_backend::spclient::{OutputList, SpClient};
|
||||||
|
|
||||||
use img_parts::jpeg::Jpeg;
|
use img_parts::jpeg::Jpeg;
|
||||||
use img_parts::{ImageEXIF, ImageICC};
|
use img_parts::{ImageEXIF, ImageICC};
|
||||||
|
|
||||||
use scrypt::{
|
use scrypt::{
|
||||||
password_hash::{
|
password_hash::{rand_core::OsRng, PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||||
rand_core::OsRng,
|
Scrypt,
|
||||||
PasswordHash, PasswordHasher, PasswordVerifier, SaltString
|
|
||||||
},
|
|
||||||
Scrypt
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//extern crate shamir;
|
//extern crate shamir;
|
||||||
@ -85,6 +83,13 @@ impl User {
|
|||||||
|
|
||||||
//part1 enc
|
//part1 enc
|
||||||
let pwd_hash_part1 = from_hex_to_b64(&sha_256(&format!("{}{}",password, &random_seed1)));
|
let pwd_hash_part1 = from_hex_to_b64(&sha_256(&format!("{}{}",password, &random_seed1)));
|
||||||
|
|
||||||
|
//split recover spend key
|
||||||
|
let (part1_key, part2_key) =
|
||||||
|
priv_recover_spend_key.split_at(priv_recover_spend_key.len() / 2);
|
||||||
|
|
||||||
|
//part1 enc
|
||||||
|
let pwd_hash_part1 = from_hex_to_b64(&sha_256(&format!("{}{}", password, &random_seed1)));
|
||||||
let key_enc_part1 = KeyEncryption::new(None, Some(pwd_hash_part1.clone()), None);
|
let key_enc_part1 = KeyEncryption::new(None, Some(pwd_hash_part1.clone()), None);
|
||||||
let part1_key_enc = key_enc_part1.enc_string(part1_key.to_string());
|
let part1_key_enc = key_enc_part1.enc_string(part1_key.to_string());
|
||||||
//part2 enc
|
//part2 enc
|
||||||
@ -92,11 +97,20 @@ impl User {
|
|||||||
let key_enc_part2 = KeyEncryption::new(None, Some(pwd_hash_part2.clone()), None);
|
let key_enc_part2 = KeyEncryption::new(None, Some(pwd_hash_part2.clone()), None);
|
||||||
let part2_key_enc = key_enc_part2.enc_string(part2_key.to_string());
|
let part2_key_enc = key_enc_part2.enc_string(part2_key.to_string());
|
||||||
//image recover
|
//image recover
|
||||||
let image_recover = ImageRecover::new(image_to_recover, &random_seed1, &random_seed2,&part1_key_enc);
|
let image_recover = ImageRecover::new(
|
||||||
|
image_to_recover,
|
||||||
|
&random_seed1,
|
||||||
|
&random_seed2,
|
||||||
|
&part1_key_enc,
|
||||||
|
);
|
||||||
//image revoke
|
//image revoke
|
||||||
//let priv_revoke_spend_key = wallet.priv_revoke_spend_key.to_owned();
|
//let priv_revoke_spend_key = wallet.priv_revoke_spend_key.to_owned();
|
||||||
//let priv_revoke_scan_key = wallet.priv_revoke_scan_key.to_owned();
|
//let priv_revoke_scan_key = wallet.priv_revoke_scan_key.to_owned();
|
||||||
let image_revoke = ImageRevoke::new(image_to_revoke,&priv_revoke_spend_key,&priv_revoke_scan_key);
|
let image_revoke = ImageRevoke::new(
|
||||||
|
image_to_revoke,
|
||||||
|
&priv_revoke_spend_key,
|
||||||
|
&priv_revoke_scan_key,
|
||||||
|
);
|
||||||
//create shardings
|
//create shardings
|
||||||
let sharding = Sharding::new(&part2_key_enc, 10u8); //nMembers = 10 for testing, need to recover nmember elsewhere
|
let sharding = Sharding::new(&part2_key_enc, 10u8); //nMembers = 10 for testing, need to recover nmember elsewhere
|
||||||
//Pre ID
|
//Pre ID
|
||||||
@ -109,11 +123,12 @@ impl User {
|
|||||||
//Receive List Items (PCD)
|
//Receive List Items (PCD)
|
||||||
|
|
||||||
console::log_1(&"authentication: ok".into());
|
console::log_1(&"authentication: ok".into());
|
||||||
User {image_recover,
|
User {
|
||||||
|
image_recover,
|
||||||
image_revoke,
|
image_revoke,
|
||||||
sharding,
|
sharding,
|
||||||
pre_id,
|
pre_id,
|
||||||
recovered_spend_key:None
|
recovered_spend_key: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,36 +158,36 @@ impl User {
|
|||||||
fn recover_part1(password: &str, random_seed1: &str, part1_key_enc: &str) -> String {
|
fn recover_part1(password: &str, random_seed1: &str, part1_key_enc: &str) -> String {
|
||||||
let pwd_hash_part1 = from_hex_to_b64(&sha_256(&format!("{}{}", password, random_seed1)));
|
let pwd_hash_part1 = from_hex_to_b64(&sha_256(&format!("{}{}", password, random_seed1)));
|
||||||
let key_dec_part1 = KeyEncryption::new(None, Some(pwd_hash_part1), None);
|
let key_dec_part1 = KeyEncryption::new(None, Some(pwd_hash_part1), None);
|
||||||
let part1_key_recovered = key_dec_part1.decode(part1_key_enc.to_string()).unwrap_or_else(|_| "".to_string());
|
let part1_key_recovered = key_dec_part1
|
||||||
|
.decode(part1_key_enc.to_string())
|
||||||
|
.unwrap_or_else(|_| "".to_string());
|
||||||
part1_key_recovered
|
part1_key_recovered
|
||||||
}
|
}
|
||||||
|
|
||||||
fn recover_part2(password: &str, random_seed2: &str, shares_vec: Vec<Vec<u8>>) -> String {
|
fn recover_part2(password: &str, random_seed2: &str, shares_vec: Vec<Vec<u8>>) -> String {
|
||||||
let quorum_sharding = (Sharding::QUORUM_SHARD * f32::from(shares_vec.len() as u8)).round() as u8;
|
let quorum_sharding =
|
||||||
|
(Sharding::QUORUM_SHARD * f32::from(shares_vec.len() as u8)).round() as u8;
|
||||||
let part2_key_enc = SecretData::recover_secret(quorum_sharding, shares_vec).unwrap();
|
let part2_key_enc = SecretData::recover_secret(quorum_sharding, shares_vec).unwrap();
|
||||||
let pwd_hash_part2 = from_hex_to_b64(&sha_256(&format!("{}{}", password, random_seed2)));
|
let pwd_hash_part2 = from_hex_to_b64(&sha_256(&format!("{}{}", password, random_seed2)));
|
||||||
let key_dec_part2 = KeyEncryption::new(None, Some(pwd_hash_part2), None);
|
let key_dec_part2 = KeyEncryption::new(None, Some(pwd_hash_part2), None);
|
||||||
let part2_key_recovered = key_dec_part2.decode(part2_key_enc).unwrap_or_else(|_| "".to_string());
|
let part2_key_recovered = key_dec_part2
|
||||||
|
.decode(part2_key_enc)
|
||||||
|
.unwrap_or_else(|_| "".to_string());
|
||||||
part2_key_recovered
|
part2_key_recovered
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//not used
|
//not used
|
||||||
pub fn pbkdf2(password: &str, data: &str) -> String {
|
pub fn pbkdf2(password: &str, data: &str) -> String {
|
||||||
let data_salt = data.trim_end_matches('=');
|
let data_salt = data.trim_end_matches('=');
|
||||||
let salt = SaltString::from_b64(data_salt)
|
let salt = SaltString::from_b64(data_salt)
|
||||||
.map(|s| { s })
|
.map(|s| s)
|
||||||
.unwrap_or_else(|_| {
|
.unwrap_or_else(|_| panic!("Failed to parse salt value from base64 string"));
|
||||||
panic!("Failed to parse salt value from base64 string")
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut password_hash = String::new();
|
let mut password_hash = String::new();
|
||||||
if let Ok(pwd) = Scrypt.hash_password(password.as_bytes(), &salt) {
|
if let Ok(pwd) = Scrypt.hash_password(password.as_bytes(), &salt) {
|
||||||
password_hash.push_str(&pwd.to_string());
|
password_hash.push_str(&pwd.to_string());
|
||||||
}
|
}
|
||||||
sha_256(&password_hash)
|
sha_256(&password_hash)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_image_recover(&self) -> Vec<u8> {
|
pub fn get_image_recover(&self) -> Vec<u8> {
|
||||||
@ -190,7 +205,6 @@ impl User {
|
|||||||
// Test sharing JS side
|
// Test sharing JS side
|
||||||
pub fn get_shares(&self) -> Vec<String> {
|
pub fn get_shares(&self) -> Vec<String> {
|
||||||
self.sharding.shares_format_str.clone()
|
self.sharding.shares_format_str.clone()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Test sharing Js side
|
//Test sharing Js side
|
||||||
@ -204,11 +218,9 @@ impl User {
|
|||||||
.filter_map(|s| s.trim().parse().ok())
|
.filter_map(|s| s.trim().parse().ok())
|
||||||
.collect();
|
.collect();
|
||||||
shares_vec.push(bytes_vec);
|
shares_vec.push(bytes_vec);
|
||||||
|
|
||||||
}
|
}
|
||||||
self.sharding.recover_secrete(shares_vec.clone())
|
self.sharding.recover_secrete(shares_vec.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
@ -217,7 +229,8 @@ pub struct ImageRecover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ImageRecover {
|
impl ImageRecover {
|
||||||
pub fn new(image_to_recover: &[u8],
|
pub fn new(
|
||||||
|
image_to_recover: &[u8],
|
||||||
random_seed1: &str,
|
random_seed1: &str,
|
||||||
random_seed2: &str,
|
random_seed2: &str,
|
||||||
part1_key_enc: &str,
|
part1_key_enc: &str,
|
||||||
@ -231,10 +244,9 @@ impl ImageRecover{
|
|||||||
let data = serde_json::to_string(&data_exif_json).unwrap();
|
let data = serde_json::to_string(&data_exif_json).unwrap();
|
||||||
let image_recover = write_exif(image_to_recover, &data);
|
let image_recover = write_exif(image_to_recover, &data);
|
||||||
ImageRecover {
|
ImageRecover {
|
||||||
image_recover_bytes: image_recover.expect("Image recover not generated!")
|
image_recover_bytes: image_recover.expect("Image recover not generated!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
@ -242,10 +254,10 @@ pub struct ImageRevoke {
|
|||||||
image_revoke_bytes: Vec<u8>,
|
image_revoke_bytes: Vec<u8>,
|
||||||
}
|
}
|
||||||
impl ImageRevoke {
|
impl ImageRevoke {
|
||||||
pub fn new(image_to_revoke: &[u8],
|
pub fn new(
|
||||||
|
image_to_revoke: &[u8],
|
||||||
priv_revoke_spend_key: &str,
|
priv_revoke_spend_key: &str,
|
||||||
priv_revoke_scan_key: &str,
|
priv_revoke_scan_key: &str,
|
||||||
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let data_exif_json = json!({
|
let data_exif_json = json!({
|
||||||
"priv_revoke_spend_key":priv_revoke_spend_key,
|
"priv_revoke_spend_key":priv_revoke_spend_key,
|
||||||
@ -255,46 +267,44 @@ impl ImageRevoke{
|
|||||||
let data = serde_json::to_string(&data_exif_json).unwrap();
|
let data = serde_json::to_string(&data_exif_json).unwrap();
|
||||||
let image_revoke = write_exif(image_to_revoke, &data);
|
let image_revoke = write_exif(image_to_revoke, &data);
|
||||||
ImageRevoke {
|
ImageRevoke {
|
||||||
image_revoke_bytes: image_revoke.expect("Image revoke not generated!")
|
image_revoke_bytes: image_revoke.expect("Image revoke not generated!"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Serialize, Deserialize, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct Sharding {
|
pub struct Sharding {
|
||||||
shares_vec: Vec<Vec<u8>>,
|
shares_vec: Vec<Vec<u8>>,
|
||||||
shares_format_str: Vec<String>,
|
shares_format_str: Vec<String>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sharding {
|
impl Sharding {
|
||||||
const QUORUM_SHARD: f32 = 0.80_f32;
|
const QUORUM_SHARD: f32 = 0.80_f32;
|
||||||
pub fn new(
|
pub fn new(part2_key_enc: &str, number_members: u8) -> Self {
|
||||||
part2_key_enc: &str,
|
|
||||||
number_members: u8,
|
|
||||||
)->Self{
|
|
||||||
let secret_data = SecretData::with_secret(part2_key_enc, number_members);
|
let secret_data = SecretData::with_secret(part2_key_enc, number_members);
|
||||||
let mut shares_format_str: Vec<String> = Vec::new();
|
let mut shares_format_str: Vec<String> = Vec::new();
|
||||||
let shares_vec = (1..=number_members).map(|i| match secret_data.get_share(i)
|
let shares_vec = (1..=number_members)
|
||||||
{
|
.map(|i| match secret_data.get_share(i) {
|
||||||
Ok(share) => {
|
Ok(share) => {
|
||||||
let string = format!("[{}]", share.clone().iter()
|
let string = format!(
|
||||||
|
"[{}]",
|
||||||
|
share
|
||||||
|
.clone()
|
||||||
|
.iter()
|
||||||
.map(|b| format!("{}", b))
|
.map(|b| format!("{}", b))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(","));
|
.join(",")
|
||||||
|
);
|
||||||
shares_format_str.push(string.clone());
|
shares_format_str.push(string.clone());
|
||||||
share
|
share
|
||||||
},
|
|
||||||
Err(_) => panic!("Not able to recover the shares!"),
|
|
||||||
}
|
}
|
||||||
).collect::<Vec<_>>();
|
Err(_) => panic!("Not able to recover the shares!"),
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Sharding {
|
Sharding {
|
||||||
shares_vec,
|
shares_vec,
|
||||||
shares_format_str
|
shares_format_str,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,9 +317,7 @@ impl Sharding{
|
|||||||
//associated functions
|
//associated functions
|
||||||
pub fn generate_random_key(length: usize) -> String {
|
pub fn generate_random_key(length: usize) -> String {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let random_bytes: Vec<u8> = (0..length)
|
let random_bytes: Vec<u8> = (0..length).map(|_| rng.gen_range(0x00..=0xFF)).collect();
|
||||||
.map(|_| rng.gen_range(0x00..=0xFF))
|
|
||||||
.collect();
|
|
||||||
base64::encode(random_bytes)
|
base64::encode(random_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +338,6 @@ pub fn sha_256(data: &str)-> String{
|
|||||||
Ok(output_image.to_vec())
|
Ok(output_image.to_vec())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn read_exif(image: &[u8]) -> Result<Vec<u8>, String> {
|
pub fn read_exif(image: &[u8]) -> Result<Vec<u8>, String> {
|
||||||
let image_bytes = Bytes::from(image.to_vec());
|
let image_bytes = Bytes::from(image.to_vec());
|
||||||
let jpeg = Jpeg::from_bytes(image_bytes).unwrap();
|
let jpeg = Jpeg::from_bytes(image_bytes).unwrap();
|
||||||
@ -355,13 +362,19 @@ pub fn from_hex_to_b58(hex_string: &str)-> String{
|
|||||||
//change for return Result?
|
//change for return Result?
|
||||||
pub fn from_b58_to_hex(base58_string: &str) -> String {
|
pub fn from_b58_to_hex(base58_string: &str) -> String {
|
||||||
let decoded_data = bs58::decode(base58_string.to_owned()).into_vec().unwrap();
|
let decoded_data = bs58::decode(base58_string.to_owned()).into_vec().unwrap();
|
||||||
let hex_string = decoded_data.iter().map(|b| format!("{:02x}", b)).collect::<String>();
|
let hex_string = decoded_data
|
||||||
|
.iter()
|
||||||
|
.map(|b| format!("{:02x}", b))
|
||||||
|
.collect::<String>();
|
||||||
hex_string
|
hex_string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_b64_to_hex(base64_string: &str) -> String {
|
fn from_b64_to_hex(base64_string: &str) -> String {
|
||||||
let decoded_data = base64::decode(base64_string).unwrap();
|
let decoded_data = base64::decode(base64_string).unwrap();
|
||||||
let hex_string = decoded_data.iter().map(|b| format!("{:02x}", b)).collect::<String>();
|
let hex_string = decoded_data
|
||||||
|
.iter()
|
||||||
|
.map(|b| format!("{:02x}", b))
|
||||||
|
.collect::<String>();
|
||||||
hex_string
|
hex_string
|
||||||
}
|
}
|
||||||
fn from_hex_to_b64(hex_string: &str) -> String {
|
fn from_hex_to_b64(hex_string: &str) -> String {
|
||||||
@ -369,6 +382,3 @@ fn from_hex_to_b64(hex_string:&str)->String{
|
|||||||
let base64_string = base64::encode(decoded_data);
|
let base64_string = base64::encode(decoded_data);
|
||||||
base64_string
|
base64_string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user