Skip to content

Commit 99851e1

Browse files
committed
more checkmate
1 parent 9933af8 commit 99851e1

5 files changed

Lines changed: 13 additions & 25 deletions

File tree

R/domain_report.R

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,11 @@
3030
#' summary(report1)
3131
#' }
3232

33-
domain_report <- function(domain, ...) {
34-
# Handle missing argument
35-
if (missing(domain)) {
36-
stop(virustotal_validation_error(
37-
message = "Domain must be provided",
38-
parameter = "domain",
39-
value = "missing"
40-
))
41-
}
42-
43-
# Handle NULL before checkmate validation
33+
domain_report <- function(domain = NULL, ...) {
34+
# Handle NULL argument
4435
if (is.null(domain)) {
4536
stop(virustotal_validation_error(
46-
message = "Domain cannot be NULL",
37+
message = "Domain must be provided",
4738
parameter = "domain",
4839
value = "NULL"
4940
))

R/rescan_file.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323

2424
rescan_file <- function(hash = NULL, ...) {
2525

26-
if (is.null(hash) || !is.character(hash) || nchar(hash) == 0) {
27-
stop("Must specify a valid file hash (MD5, SHA1, or SHA256).\n")
28-
}
26+
# Validate hash using checkmate
27+
assert_character(hash, len = 1, any.missing = FALSE, min.chars = 1)
2928

3029
res <- virustotal_POST(path = paste0("files/", hash, "/analyse"), ...)
3130

R/scan_url.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323

2424
scan_url <- function(url = NULL, ...) {
2525

26-
if (is.null(url) || !is.character(url) || nchar(url) == 0) {
27-
stop("Must specify a valid URL.\n")
28-
}
26+
# Validate URL using checkmate
27+
assert_character(url, len = 1, any.missing = FALSE, min.chars = 1)
2928

3029
res <- virustotal_POST(path = "urls",
3130
body = list(url = url), ...)

R/set_key.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
#' Sys.getenv("VirustotalToken")
2020
#' }
2121

22-
set_key <- function(api_key) {
23-
# Handle missing argument
24-
if (missing(api_key)) {
22+
set_key <- function(api_key = NULL) {
23+
# Handle NULL argument
24+
if (is.null(api_key)) {
2525
stop(virustotal_validation_error(
2626
message = "API key must be provided",
2727
parameter = "api_key",
28-
value = "missing"
28+
value = "NULL"
2929
))
3030
}
3131

R/url_report.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727

2828
url_report <- function(url_id = NULL, ...) {
2929

30-
if (is.null(url_id) || !is.character(url_id) || nchar(url_id) == 0) {
31-
stop("Must specify a valid URL or URL ID.\n")
32-
}
30+
# Validate URL ID using checkmate
31+
assert_character(url_id, len = 1, any.missing = FALSE, min.chars = 1)
3332

3433
# If it looks like a URL, encode it to base64 (VirusTotal v3 requirement)
3534
if (grepl("^https?://", url_id)) {

0 commit comments

Comments
 (0)