From a1beff5e658e904f96cebe0e3636aacee77d1068 Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Fri, 4 Oct 2024 23:18:52 +0530 Subject: [PATCH 1/2] fix --- aderyn/src/lib.rs | 22 ++++++++++++---------- aderyn/src/main.rs | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/aderyn/src/lib.rs b/aderyn/src/lib.rs index 31752b5b..fae7dc4e 100644 --- a/aderyn/src/lib.rs +++ b/aderyn/src/lib.rs @@ -1,7 +1,7 @@ use aderyn_driver::detector::{get_all_detectors_names, get_issue_detector_by_name, IssueSeverity}; use semver::Version; use serde_json::Value; -use std::{fs::File, io::Write, path::PathBuf, str::FromStr}; +use std::{error::Error, fs::File, io::Write, path::PathBuf, str::FromStr}; use strum::IntoEnumIterator; pub fn create_aderyn_toml_file_at(directory: String) { @@ -88,21 +88,23 @@ fn right_pad(s: &str, by: usize) -> String { pub static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); -pub fn aderyn_is_currently_running_newest_version() -> Result { +pub fn aderyn_is_currently_running_newest_version() -> Option { let client = reqwest::blocking::Client::builder() .user_agent(APP_USER_AGENT) - .build()?; + .build() + .expect("client is unable to initialize"); let latest_version_checker = client .get("https://api.github.com/repos/Cyfrin/aderyn/releases/latest") - .send()?; + .send() + .ok()?; - let data = latest_version_checker.json::()?; - let newest = - Version::parse(data["tag_name"].as_str().unwrap().replace('v', "").as_str()).unwrap(); - let current = Version::parse(env!("CARGO_PKG_VERSION")).unwrap(); + let data = latest_version_checker.json::().ok()?; + let version_string = data["tag_name"].as_str()?; + let newest = Version::parse(version_string.replace('v', "").as_str()).ok()?; + let current = Version::parse(env!("CARGO_PKG_VERSION")).expect("Pkg version not available"); - Ok(current >= newest) + Some(current >= newest) } #[cfg(test)] @@ -111,6 +113,6 @@ mod latest_version_checker_tests { #[test] fn can_get_latest_version_from_crate_registry() { - assert!(aderyn_is_currently_running_newest_version().is_ok()) + assert!(aderyn_is_currently_running_newest_version().is_some()) } } diff --git a/aderyn/src/main.rs b/aderyn/src/main.rs index eda36a23..8c1a55df 100644 --- a/aderyn/src/main.rs +++ b/aderyn/src/main.rs @@ -141,7 +141,7 @@ fn main() { // Check for updates if !cmd_args.skip_update_check { - if let Ok(yes) = aderyn_is_currently_running_newest_version() { + if let Some(yes) = aderyn_is_currently_running_newest_version() { if !yes { println!(); println!("NEW VERSION OF ADERYN AVAILABLE! Please run `cyfrinup` to upgrade."); From 81e99da4fd6020e87e2351db03d0bf00ad2888de Mon Sep 17 00:00:00 2001 From: TilakMaddy Date: Fri, 4 Oct 2024 23:22:20 +0530 Subject: [PATCH 2/2] clippy --- aderyn/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aderyn/src/lib.rs b/aderyn/src/lib.rs index fae7dc4e..b34af156 100644 --- a/aderyn/src/lib.rs +++ b/aderyn/src/lib.rs @@ -1,7 +1,7 @@ use aderyn_driver::detector::{get_all_detectors_names, get_issue_detector_by_name, IssueSeverity}; use semver::Version; use serde_json::Value; -use std::{error::Error, fs::File, io::Write, path::PathBuf, str::FromStr}; +use std::{fs::File, io::Write, path::PathBuf, str::FromStr}; use strum::IntoEnumIterator; pub fn create_aderyn_toml_file_at(directory: String) {