Skip to content

Commit d4a5b6e

Browse files
committed
more checkmate
1 parent cbcedf4 commit d4a5b6e

6 files changed

Lines changed: 8 additions & 21 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ tests/testthat/virustotal_api_key
1111
*.gz
1212
/docs/
1313
docs
14+
/..Rcheck

R/download_file.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
download_file <- function(hash = NULL, output_path = NULL, ...) {
2424

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

2927
# Note: This endpoint returns raw file content, not JSON
3028
res <- GET("https://www.virustotal.com/",

R/get_file_comments.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
get_file_comments <- function(hash = NULL, limit = NULL, cursor = NULL, ...) {
2424

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

2927
res <- virustotal_GET(path = paste0("files/", hash, "/comments"),
3028
query = list(limit = limit, cursor = cursor), ...)

R/get_file_download_url.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
get_file_download_url <- function(hash = NULL, ...) {
2222

23-
if (is.null(hash) || !is.character(hash) || nchar(hash) == 0) {
24-
stop("Must specify a valid file hash (MD5, SHA1, or SHA256).\n")
25-
}
23+
assert_character(hash, len = 1, any.missing = FALSE, min.chars = 1)
2624

2725
res <- virustotal_GET(path = paste0("files/", hash, "/download_url"), ...)
2826

R/get_file_relationships.R

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@
2525
get_file_relationships <- function(hash = NULL, relationship = NULL,
2626
limit = NULL, cursor = NULL, ...) {
2727

28-
if (is.null(hash) || !is.character(hash) || nchar(hash) == 0) {
29-
stop("Must specify a valid file hash (MD5, SHA1, or SHA256).\n")
30-
}
31-
32-
if (is.null(relationship) || !is.character(relationship)) {
33-
stop("Must specify a relationship type.\n")
34-
}
28+
assert_character(hash, len = 1, any.missing = FALSE, min.chars = 1)
29+
assert_character(relationship, len = 1, any.missing = FALSE, min.chars = 1)
3530

3631
valid_relationships <- c("behaviours", "bundled_files", "compression_parents",
3732
"contacted_domains", "contacted_ips", "contacted_urls",
@@ -40,8 +35,7 @@ get_file_relationships <- function(hash = NULL, relationship = NULL,
4035
"pe_resource_parents", "similar_files", "submissions")
4136

4237
if (!relationship %in% valid_relationships) {
43-
stop("Invalid relationship type. Must be one of: ",
44-
paste(valid_relationships, collapse = ", "), "\n")
38+
stop("Invalid relationship type")
4539
}
4640

4741
res <- virustotal_GET(path = paste0("files/", hash, "/relationships/", relationship),

R/ip_report.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626
ip_report <- function(ip = NULL, ...) {
2727
# Input validation first (before API key for proper test precedence)
28-
if (is.null(ip) || !is.character(ip) || nchar(ip) == 0) {
29-
stop("Must specify a valid IP address.\n")
30-
}
28+
assert_character(ip, len = 1, any.missing = FALSE, min.chars = 1)
3129

3230
# Check API key after basic validation
3331
if (identical(Sys.getenv("VirustotalToken"), "")) {

0 commit comments

Comments
 (0)