From d03a8ae05e32f3648fda2cbd5698658a5ae2f64b Mon Sep 17 00:00:00 2001 From: boB Rudis Date: Sat, 28 Apr 2018 22:43:40 -0400 Subject: [PATCH] turned errors into warnings with NA return --- R/tlsh-hash.R | 12 ++++++++++-- man/tlsh_simple_hash.Rd | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/tlsh-hash.R b/R/tlsh-hash.R index 672f37e..3b04527 100644 --- a/R/tlsh-hash.R +++ b/R/tlsh-hash.R @@ -1,15 +1,23 @@ #' Compute TLSH hash for a character or raw vector and return hash fingerprint #' +#' A warning will be issued if the input byte stream is <50 bytes. +#' #' @md #' @param x length 1 `character` or `raw` vector #' @export tlsh_simple_hash <- function(x) { if (inherits(x, "character")) { x <- x[1] - if (nchar(x) < 50L) stop("Byte stream minimum length is 50 bytes", call.=FALSE) + if (nchar(x) < 50L) { + warning("Byte stream minimum length is 50 bytes.") + return(NA_character_) + } tlsh_simple_hash_c(x) } else if (inherits(x, "raw")) { - if (length(x) < 50L) stop("Byte stream minimum length is 50 bytes", call.=FALSE) + if (length(x) < 50L) { + warning("Byte stream minimum length is 50 bytes.") + return(NA_character_) + } tlsh_simple_hash_r(x) } else { NULL diff --git a/man/tlsh_simple_hash.Rd b/man/tlsh_simple_hash.Rd index 384969c..febf71e 100644 --- a/man/tlsh_simple_hash.Rd +++ b/man/tlsh_simple_hash.Rd @@ -10,5 +10,5 @@ tlsh_simple_hash(x) \item{x}{length 1 \code{character} or \code{raw} vector} } \description{ -Compute TLSH hash for a character or raw vector and return hash fingerprint +A warning will be issued if the input byte stream is <50 bytes. }