Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] read encrypted xlsx files #692

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.DS_Store
.vscode/*
src/*.o
src/xlcpp/*.o
src/*.so
src/*.dll
src-i386/*.dll
Expand Down
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Config/testthat/parallel: false
Config/testthat/start-first: aaa
SystemRequirements: C++20

4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

read_encryption <- function(PATH, OUT, PASSWORD) {
invisible(.Call(`_openxlsx2_read_encryption`, PATH, OUT, PASSWORD))
}

#' Check if path is to long to be an R file path
#' @param path the file path used in file.exists()
#' @noRd
Expand Down
9 changes: 9 additions & 0 deletions R/wb_load.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ wb_load <- function(
...
) {

password <- NULL
standardize_case_names(...)

file <- xlsx_file %||% file
Expand All @@ -49,6 +50,14 @@ wb_load <- function(
stop("File does not exist.")
}

pwd <- list(...)$password

if (!is.null(pwd)) {
unencrypted_xlsx <- temp_xlsx()
read_encryption(PATH = path.expand(file), OUT = unencrypted_xlsx, PASSWORD = pwd)
file <- unencrypted_xlsx
}

## create temp dir
xmlDir <- temp_dir("_openxlsx_wb_load")

Expand Down
35 changes: 34 additions & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
PKG_CPPFLAGS = -I. -I../inst/include/pugixml

PKG_CXXFLAGS = -I. -Ixlcpp -I../inst/include/pugixml -DXLCPP_EXPORT

PKG_LIBS = -Lpugixml -Lxlcpp

PKGROOT = ./xlcpp

OBJECTS = decrypt.o \
helper_functions.o \
load_workbook.o \
pugi.o \
strings_xml.o \
styles_xml.o \
write_file.o \
$(PKGROOT)/aes.o \
$(PKGROOT)/b64.o \
$(PKGROOT)/cfbf.o \
$(PKGROOT)/sha1.o \
$(PKGROOT)/sha512.o \
$(PKGROOT)/xlcpp.o \
$(PKGROOT)/xml-reader.o \
RcppExports.o

XLCPP = $(PKGROOT)/aes.cpp \
$(PKGROOT)/b64.cpp \
$(PKGROOT)/cfbf.cpp \
$(PKGROOT)/sha1.cpp \
$(PKGROOT)/sha512.cpp \
$(PKGROOT)/xml-reader.cpp \
$(PKGROOT)/xlcpp.cpp

PUGIXML = ../inst/include/pugixml/pugixml.cpp

# CXX_STD=CXX20
13 changes: 13 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// read_encryption
void read_encryption(std::string PATH, std::string OUT, std::string PASSWORD);
RcppExport SEXP _openxlsx2_read_encryption(SEXP PATHSEXP, SEXP OUTSEXP, SEXP PASSWORDSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type PATH(PATHSEXP);
Rcpp::traits::input_parameter< std::string >::type OUT(OUTSEXP);
Rcpp::traits::input_parameter< std::string >::type PASSWORD(PASSWORDSEXP);
read_encryption(PATH, OUT, PASSWORD);
return R_NilValue;
END_RCPP
}
// to_long
bool to_long(std::string path);
RcppExport SEXP _openxlsx2_to_long(SEXP pathSEXP) {
Expand Down Expand Up @@ -842,6 +854,7 @@ END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_openxlsx2_read_encryption", (DL_FUNC) &_openxlsx2_read_encryption, 3},
{"_openxlsx2_to_long", (DL_FUNC) &_openxlsx2_to_long, 1},
{"_openxlsx2_openxlsx2_type", (DL_FUNC) &_openxlsx2_openxlsx2_type, 1},
{"_openxlsx2_int_to_col", (DL_FUNC) &_openxlsx2_int_to_col, 1},
Expand Down
11 changes: 11 additions & 0 deletions src/decrypt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <xlcpp/xlcpp.h>

// [[Rcpp::export]]
void read_encryption(std::string PATH, std::string OUT, std::string PASSWORD) {


xlcpp::workbook wb(PATH, PASSWORD, OUT);

// this creates xlcpp workbook, not the unzipped xlsx file
// wb.save(OUT);
}
Loading