pow_256 veresion bump

This commit is contained in:
Aravinth Manivannan 2021-03-08 18:33:35 +05:30
parent 4fe205c73a
commit d53d35468e
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
4 changed files with 14 additions and 20 deletions

10
Cargo.lock generated
View file

@ -102,9 +102,9 @@ dependencies = [
[[package]]
name = "async-trait"
version = "0.1.46"
version = "0.1.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4968268c4b1be4c2ee4a619dba411ec2db09acde6c26da368cb01a330b60f06c"
checksum = "7e098e9c493fdf92832223594d9a164f96bdf17ba81a42aff86f85c76768726a"
dependencies = [
"proc-macro2",
"quote",
@ -729,7 +729,7 @@ dependencies = [
"actix-rt",
"derive_builder",
"derive_more",
"pow_sha256 0.1.0",
"pow_sha256 0.2.0",
"rand 0.8.3",
"serde",
"serde_json",
@ -983,8 +983,8 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pow_sha256"
version = "0.1.0"
source = "git+https://github.com/mcaptcha/pow_sha256#0bfbce0185f111b2eb8c14ff74d95dde5af22388"
version = "0.2.0"
source = "git+https://github.com/mcaptcha/pow_sha256#d0889fc9008e63795b024b57432ed0034a703d0b"
dependencies = [
"bincode",
"derive_builder",

View file

@ -24,7 +24,7 @@ derive_builder = "0.9"
derive_more = "0.99"
rand = "0.8"
pow_sha256 = { version = "0.1", git = "https://github.com/mcaptcha/pow_sha256" }
pow_sha256 = { version = "0.2", git = "https://github.com/mcaptcha/pow_sha256" }
[dev-dependencies]
actix-rt = "1"

View file

@ -75,7 +75,6 @@ where
pub async fn verify_pow(&self, work: Work) -> CaptchaResult<bool> {
use crate::cache::messages::Retrive;
use crate::utils::get_difficulty;
let string = work.string.clone();
let msg = Retrive(string.clone());
@ -83,10 +82,7 @@ where
let pow: PoW<String> = work.into();
match difficulty {
Ok(Some(difficulty)) => {
if self
.pow
.is_sufficient_difficulty(&pow, get_difficulty(difficulty))
{
if self.pow.is_sufficient_difficulty(&pow, difficulty) {
Ok(self.pow.is_valid_proof(&pow, &string))
} else {
Err(CaptchaError::InsuffiencientDifficulty)
@ -122,9 +118,9 @@ mod tests {
use pow_sha256::ConfigBuilder;
use super::*;
use crate::cache::HashCache;
use crate::master::*;
use crate::mcaptcha::tests::*;
use crate::{cache::HashCache, utils::get_difficulty};
const MCAPTCHA_NAME: &str = "batsense.net";
@ -170,11 +166,11 @@ mod tests {
let work_req = actors.get_pow(MCAPTCHA_NAME.into()).await.unwrap();
let config = get_config();
let difficulty = get_difficulty(work_req.difficulty_factor);
let work = config.prove_work(&work_req.string, difficulty).unwrap();
let work = config
.prove_work(&work_req.string, work_req.difficulty_factor)
.unwrap();
let difficulty = 1;
let insufficient_work = config.prove_work(&work_req.string, difficulty).unwrap();
let insufficient_work = config.prove_work(&work_req.string, 1).unwrap();
let insufficient_work_payload = Work {
string: work_req.string.clone(),
result: insufficient_work.result,

View file

@ -1,3 +1,5 @@
// utility function to get a randomly generated string
// of size len
pub fn get_random(len: usize) -> String {
use std::iter;
@ -11,7 +13,3 @@ pub fn get_random(len: usize) -> String {
.take(len)
.collect::<String>()
}
pub fn get_difficulty(difficulty_factor: u32) -> u128 {
u128::max_value() - u128::max_value() / difficulty_factor as u128
}