Browse Source

embed 1

pull/1/head
boB Rudis 4 years ago
parent
commit
a85a47945f
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      NAMESPACE
  2. 8
      R/hash-file.R
  3. 28
      R/split-hash.R
  4. 26
      man/split_hash.Rd

1
NAMESPACE

@ -5,6 +5,7 @@ export(hash_compare)
export(hash_con)
export(hash_file)
export(hash_raw)
export(split_hash)
importFrom(Rcpp,sourceCpp)
importFrom(magrittr,"%>%")
useDynLib(ssdeepr, .registration = TRUE)

8
R/hash-file.R

@ -14,12 +14,12 @@
#' hash_compare(hashes$hash[1], hashes$hash[4])
hash_file <- function(path) {
path <- path.expand(path)
lapply(path, function(.x) {
if (file.exists(.x)) {
hash <- int_hash_file(.x)
xpath <- path.expand(.x)
if (file.exists(xpath)) {
hash <- int_hash_file(xpath)
} else {
hash <- NA_character_
}

28
R/split-hash.R

@ -0,0 +1,28 @@
#' Splits an ssdeep hash string into component parts
#'
#' ssdeep hashes consists of three parts, separated by `:`:
#' - chunk size : size of the chunks in rest of the hash
#' - chunk : where each character represents a part of the file of length "chunk size"
#' - double chunk : hash computation where "chunk size" = 2 * "chunk size"
#' This function splits the single has string into three component parts.
#'
#' @param x character vector of ssdeep hashes
#' @return data frame
#' @export
#' @examples
#' split_hash(hash_con(url("https://en.wikipedia.org/wiki/Donald_Knuth")))
split_hash <- function(x) {
components <- strsplit(x, ":", fixed = TRUE)
lapply(components, function(.x) {
as.data.frame(as.list(setNames(.x, c("chunk_size", "chunk", "double_chunk"))), stringsAsFactors = FALSE)
}) -> out
out <- do.call(rbind.data.frame, out)
class(out) <- c("tbl_df", "tbl", "data.frame")
out[["chunk_size"]] <- as.integer(out[["chunk_size"]])
out
}

26
man/split_hash.Rd

@ -0,0 +1,26 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/split-hash.R
\name{split_hash}
\alias{split_hash}
\title{Splits an ssdeep hash string into component parts}
\usage{
split_hash(x)
}
\arguments{
\item{x}{character vector of ssdeep hashes}
}
\value{
data frame
}
\description{
ssdeep hashes consists of three parts, separated by \code{:}:
\itemize{
\item chunk size : size of the chunks in rest of the hash
\item chunk : where each character represents a part of the file of length "chunk size"
\item double chunk : hash computation where "chunk size" = 2 * "chunk size"
This function splits the single has string into three component parts.
}
}
\examples{
split_hash(hash_con(url("https://en.wikipedia.org/wiki/Donald_Knuth")))
}
Loading…
Cancel
Save