From e51224fb3e7fa363abe76ff2b83f3360bd2df11f Mon Sep 17 00:00:00 2001 From: gothub Date: Wed, 26 Aug 2020 15:41:30 -0700 Subject: [PATCH] Use 'SHA-256' checksum for sysmeta/object uploads (#257) --- R/D1Node.R | 4 ++-- R/MNode.R | 12 ++++++------ man/MNode-class.Rd | 4 ++-- man/archive.Rd | 4 ++-- man/createObject.Rd | 4 ++-- man/getChecksum.Rd | 4 ++-- tests/testthat/test.D1Client.R | 4 ++-- tests/testthat/test.MNode.R | 26 +++++++++++++------------- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/R/D1Node.R b/R/D1Node.R index 7b1d52a..1abbdc1 100644 --- a/R/D1Node.R +++ b/R/D1Node.R @@ -159,8 +159,8 @@ setMethod("D1Node", signature("XMLInternalElementNode"), function(xml) { #' newid <- paste("urn:uuid:", UUIDgenerate(), sep="") #' format <- "text/csv" #' size <- file.info(csvfile)$size -#' sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) -#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1) +#' sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) +#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256) #' sysmeta <- addAccessRule(sysmeta, "public", "read") #' # Create (upload) the object to DataONE (requires authentication) #' \dontrun{ diff --git a/R/MNode.R b/R/MNode.R index ad0a771..df0df40 100644 --- a/R/MNode.R +++ b/R/MNode.R @@ -71,9 +71,9 @@ #' write.csv(testdf, csvfile, row.names=FALSE) #' f <- "text/csv" #' size <- file.info(csvfile)$size -#' sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) +#' sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) #' sysmeta <- new("SystemMetadata", identifier=newid, formatId=f, size=size, -#' checksum=sha1, originMemberNode=mnid, authoritativeMemberNode=mnid) +#' checksum=sha256, originMemberNode=mnid, authoritativeMemberNode=mnid) #' # Upload data to DataONE (requires authentication) #' \dontrun{ #' response <- createObject(mn, newid, csvfile, sysmeta) @@ -280,9 +280,9 @@ setMethod("getSystemMetadata", signature("MNode"), function(x, pid) { }) #' @rdname getChecksum -#' @param checksumAlgorithm The algorithm used to calculate the checksum. Default="SHA-1" +#' @param checksumAlgorithm The algorithm used to calculate the checksum. Default="SHA-256" #' @export -setMethod("getChecksum", signature("MNode"), function(x, pid, checksumAlgorithm="SHA-1") { +setMethod("getChecksum", signature("MNode"), function(x, pid, checksumAlgorithm="SHA-256") { stopifnot(is.character(pid)) url <- paste(x@endpoint, "checksum", URLencode(pid, reserved=T), sep="/") response<-GET(url, query=list(checksumAlgorithm=checksumAlgorithm), user_agent(get_user_agent())) @@ -346,8 +346,8 @@ setMethod("getChecksum", signature("MNode"), function(x, pid, checksumAlgorithm= #' write.csv(testdf, csvfile, row.names=FALSE) #' format <- "text/csv" #' size <- file.info(csvfile)$size -#' sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) -#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1) +#' sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) +#' sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256) #' sysmeta <- addAccessRule(sysmeta, "public", "read") #' # Upload the data to DataONE (requires authentication) #' \dontrun{ diff --git a/man/MNode-class.Rd b/man/MNode-class.Rd index abd6d4d..de11edf 100644 --- a/man/MNode-class.Rd +++ b/man/MNode-class.Rd @@ -60,9 +60,9 @@ csvfile <- paste(tempfile(), ".csv", sep="") write.csv(testdf, csvfile, row.names=FALSE) f <- "text/csv" size <- file.info(csvfile)$size -sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) +sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) sysmeta <- new("SystemMetadata", identifier=newid, formatId=f, size=size, - checksum=sha1, originMemberNode=mnid, authoritativeMemberNode=mnid) + checksum=sha256, originMemberNode=mnid, authoritativeMemberNode=mnid) # Upload data to DataONE (requires authentication) \dontrun{ response <- createObject(mn, newid, csvfile, sysmeta) diff --git a/man/archive.Rd b/man/archive.Rd index 453450e..3f7fff9 100644 --- a/man/archive.Rd +++ b/man/archive.Rd @@ -53,8 +53,8 @@ newid <- generateIdentifier(mn, "UUID") newid <- paste("urn:uuid:", UUIDgenerate(), sep="") format <- "text/csv" size <- file.info(csvfile)$size -sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) -sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1) +sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) +sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256) sysmeta <- addAccessRule(sysmeta, "public", "read") # Create (upload) the object to DataONE (requires authentication) \dontrun{ diff --git a/man/createObject.Rd b/man/createObject.Rd index d6e6203..b46987d 100644 --- a/man/createObject.Rd +++ b/man/createObject.Rd @@ -58,8 +58,8 @@ csvfile <- paste(tempfile(), ".csv", sep="") write.csv(testdf, csvfile, row.names=FALSE) format <- "text/csv" size <- file.info(csvfile)$size -sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) -sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1) +sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) +sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256) sysmeta <- addAccessRule(sysmeta, "public", "read") # Upload the data to DataONE (requires authentication) \dontrun{ diff --git a/man/getChecksum.Rd b/man/getChecksum.Rd index 00024e6..f92a54c 100644 --- a/man/getChecksum.Rd +++ b/man/getChecksum.Rd @@ -10,7 +10,7 @@ getChecksum(x, ...) \S4method{getChecksum}{CNode}(x, pid, ...) -\S4method{getChecksum}{MNode}(x, pid, checksumAlgorithm = "SHA-1") +\S4method{getChecksum}{MNode}(x, pid, checksumAlgorithm = "SHA-256") } \arguments{ \item{x}{The CNode instance from which the checksum will be retrieved} @@ -19,7 +19,7 @@ getChecksum(x, ...) \item{pid}{The identifier of the object} -\item{checksumAlgorithm}{The algorithm used to calculate the checksum. Default="SHA-1"} +\item{checksumAlgorithm}{The algorithm used to calculate the checksum. Default="SHA-256"} } \value{ character the checksum value, with the checksum algorithm as the attribute "algorithm" diff --git a/tests/testthat/test.D1Client.R b/tests/testthat/test.D1Client.R index b464e28..bedeb71 100644 --- a/tests/testthat/test.D1Client.R +++ b/tests/testthat/test.D1Client.R @@ -95,8 +95,8 @@ test_that("D1Client getDataObject", { expect_match(getIdentifier(obj), pid) expect_match(getFormatId(obj), "text/csv") data <- getData(obj) - sha1 <- digest(data, algo="md5", serialize=FALSE, file=FALSE) - expect_match(sha1, obj@sysmeta@checksum) + sha256 <- digest(data, algo="md5", serialize=FALSE, file=FALSE) + expect_match(sha256, obj@sysmeta@checksum) }) test_that("D1Client uploadDataObject with raw data works", { diff --git a/tests/testthat/test.MNode.R b/tests/testthat/test.MNode.R index 61a7e00..26d3141 100644 --- a/tests/testthat/test.MNode.R +++ b/tests/testthat/test.MNode.R @@ -130,9 +130,9 @@ test_that("MNode describeObject() with authentication", { # Create SystemMetadata for the object format <- "text/csv" size <- file.info(csvfile)$size - sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) + sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) # specify series id for this sysmeta. This will only be used if uploading to a DataONE v2 node - sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1, + sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256, originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier) # sysmeta <- addAccessRule(sysmeta, "public", "read") # Upload the data to the MN using createObject(), checking for success and a returned identifier @@ -186,13 +186,13 @@ test_that("MNode createObject(), updateObject(), archive()", { # Create SystemMetadata for the object format <- "text/csv" size <- file.info(csvfile)$size - sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) + sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) # specify series id for this sysmeta. This will only be used if uploading to a DataONE v2 node seriesId <- UUIDgenerate() - sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1, + sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256, originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier, seriesId=seriesId) sysmeta <- addAccessRule(sysmeta, "public", "read") - expect_that(sysmeta@checksum, equals(sha1)) + expect_that(sysmeta@checksum, equals(sha256)) expect_that(sysmeta@originMemberNode, equals(mnTest@identifier)) expect_that(sysmeta@authoritativeMemberNode, equals(mnTest@identifier)) @@ -207,10 +207,10 @@ test_that("MNode createObject(), updateObject(), archive()", { csvfile <- paste(tempfile(), ".csv", sep="") write.csv(testdf, csvfile, row.names=FALSE) size <- file.info(csvfile)$size - sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) + sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) sysmeta@identifier <- updateid sysmeta@size <- size - sysmeta@checksum <- sha1 + sysmeta@checksum <- sha256 sysmeta@obsoletes <- newid newId <- updateObject(mnTest, newid, csvfile, updateid, sysmeta) expect_false(is.null(newId)) @@ -270,12 +270,12 @@ test_that("MNode createObject() with in-memory object", { # Create SystemMetadata for the object format <- "text/csv" size <- length(csvdata) - sha1 <- digest(csvdata, algo="sha1", serialize=FALSE, file=FALSE) + sha256 <- digest(csvdata, algo="sha256", serialize=FALSE, file=FALSE) # specify series id for this sysmeta. This will only be used if uploading to a DataONE v2 node - sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1) + sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256) sysmeta <- addAccessRule(sysmeta, "public", "read") - expect_that(sysmeta@checksum, equals(sha1)) + expect_that(sysmeta@checksum, equals(sha256)) # Upload the data to the MN using createObject(), checking for success and a returned identifier createdId <- createObject(mnTest, newid, sysmeta = sysmeta, dataobj=csvdata) @@ -322,10 +322,10 @@ test_that("MNode createObject() works for large files", { # Create SystemMetadata for the object format <- "text/csv" size <- file.info(csvfile)$size - sha1 <- digest(csvfile, algo="sha1", serialize=FALSE, file=TRUE) - sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha1, originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier) + sha256 <- digest(csvfile, algo="sha256", serialize=FALSE, file=TRUE) + sysmeta <- new("SystemMetadata", identifier=newid, formatId=format, size=size, checksum=sha256, originMemberNode=mnTest@identifier, authoritativeMemberNode=mnTest@identifier) sysmeta <- addAccessRule(sysmeta, "public", "read") - expect_that(sysmeta@checksum, equals(sha1)) + expect_that(sysmeta@checksum, equals(sha256)) expect_that(sysmeta@originMemberNode, equals(mnTest@identifier)) expect_that(sysmeta@authoritativeMemberNode, equals(mnTest@identifier))