From f25757fa59f4081fb37e7bf3601ef4c8e4d9bf57 Mon Sep 17 00:00:00 2001 From: freedit-dev Date: Fri, 11 Oct 2024 14:28:34 +0000 Subject: [PATCH 1/2] fix out-dated dependencies --- Cargo.toml | 7 ++----- examples/perf.rs | 12 +++++------- src/audio/mod.rs | 4 ++-- src/fonts/mod.rs | 4 ++-- src/lib.rs | 10 ++++------ 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47f81cf..0dd3adc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,16 +12,13 @@ homepage = "https://github.com/daniel-e/captcha" repository = "https://github.com/daniel-e/captcha" [dependencies] -image = { version = "0.24.2", default-features = false, features = ["png"] } +image = { version = "0.25.2", default-features = false, features = ["png"] } rand = "0.8.5" serde_json = "1.0" -base64 = "0.13" +base64 = "0.22.1" lodepng = "3.6.1" hound = { version = "3.4", optional = true } -[dev-dependencies] -time = "0.3.9" - [features] default = ["audio"] audio = ["hound"] \ No newline at end of file diff --git a/examples/perf.rs b/examples/perf.rs index 843a68f..dcdbd62 100644 --- a/examples/perf.rs +++ b/examples/perf.rs @@ -1,9 +1,7 @@ extern crate captcha; -extern crate time; use captcha::{gen, Difficulty}; -use std::thread; -use time::Instant; +use std::{thread, time::Instant}; fn main() { let n = 500; @@ -17,7 +15,7 @@ fn main() { for _ in 0..n { gen(Difficulty::Easy).as_tuple(); } - println!("done {:?} ms", b.elapsed().whole_milliseconds()); + println!("done {:?} ms", b.elapsed().as_millis()); }); threads.push(h); } @@ -28,13 +26,13 @@ fn main() { let d = b.elapsed(); println!("n : {}", n * nthreads); - println!("time in ms total : {}", d.whole_milliseconds()); + println!("time in ms total : {}", d.as_millis()); println!( "time in ms per captcha: {}", - d.whole_milliseconds() as f64 / (n * nthreads) as f64 + d.as_millis() as f64 / (n * nthreads) as f64 ); println!( "#captchs per second : {}", - (n * nthreads * 1000) / (d.whole_milliseconds() as i64) + (n * nthreads * 1000) / (d.as_millis() as i64) ); } diff --git a/src/audio/mod.rs b/src/audio/mod.rs index 34551b0..12dd0b5 100644 --- a/src/audio/mod.rs +++ b/src/audio/mod.rs @@ -1,5 +1,5 @@ #[cfg(feature = "audio")] -use base64::decode; +use base64::{engine::general_purpose, Engine}; #[cfg(feature = "audio")] use hound::Result; #[cfg(feature = "audio")] @@ -29,7 +29,7 @@ impl Audio { pub fn as_wav(&self, letter: char) -> Option> { match self.data.get(&letter) { None => None, - Some(s) => match decode(s) { + Some(s) => match general_purpose::STANDARD.decode(s) { Err(_) => None, Ok(v) => match Audio::add_noise(v) { Ok(v) => Some(v), diff --git a/src/fonts/mod.rs b/src/fonts/mod.rs index 570b544..0f0fc13 100644 --- a/src/fonts/mod.rs +++ b/src/fonts/mod.rs @@ -1,4 +1,4 @@ -use base64::decode; +use base64::{engine::general_purpose, Engine}; use serde_json; use std::collections::HashMap; @@ -11,7 +11,7 @@ pub trait Font { fn png(&self, letter: char) -> Option> { match self.png_as_base64(letter) { None => None, - Some(s) => match decode(s) { + Some(s) => match general_purpose::STANDARD.decode(s) { Err(_) => None, Ok(v) => Some(v), }, diff --git a/src/lib.rs b/src/lib.rs index 23c6813..92c73e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,6 +63,7 @@ mod samples; pub use samples::{by_name, gen, CaptchaName, Difficulty}; +use base64::{engine::general_purpose, Engine}; use filters::Filter; use fonts::{Default, Font}; use images::{Image, Pixl}; @@ -113,7 +114,6 @@ pub struct RngCaptcha { } impl RngCaptcha { - pub fn from_rng(rng: T) -> RngCaptcha { // TODO fixed width + height let w = 400; @@ -309,7 +309,8 @@ impl RngCaptcha { } pub fn as_base64(&self) -> Option { - self.as_png().map(base64::encode) + self.as_png() + .map(|png| general_purpose::STANDARD.encode(&png)) } /// Returns a tuple which contains the characters that have been added to this CAPTCHA @@ -317,10 +318,7 @@ impl RngCaptcha { /// /// Returns `None` on error. pub fn as_tuple(&self) -> Option<(String, Vec)> { - match self.as_png() { - None => None, - Some(p) => Some((self.chars_as_string(), p)), - } + self.as_png().map(|p| (self.chars_as_string(), p)) } /// Returns the supported characters of the current font. From 5a9e20322dc1cc5b192554f53e50c8ebf85cc77b Mon Sep 17 00:00:00 2001 From: freedit-dev Date: Fri, 11 Oct 2024 14:29:17 +0000 Subject: [PATCH 2/2] clippy --- src/filters/cow.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/filters/cow.rs b/src/filters/cow.rs index 75f0158..82cc36b 100644 --- a/src/filters/cow.rs +++ b/src/filters/cow.rs @@ -68,7 +68,7 @@ impl Cow { for &(x, y) in v { let mut p = i.get_pixel(x, y); p.invert(); - i.put_pixel(x as u32, y as u32, p); + i.put_pixel(x, y, p); } } }