Skip to content

Commit

Permalink
include msco/cybozu lib for cryptography
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 18, 2023
1 parent 028bf43 commit f2346fe
Show file tree
Hide file tree
Showing 103 changed files with 22,772 additions and 1 deletion.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ cran-comments.md
^inst/img$
^tests/testthat/_snaps$
^tests/testthat/testfiles$
*.o
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.RData
.DS_Store
.vscode/*
*.o
src/*.o
src/*.so
src/*.dll
Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Config/testthat/parallel: false
Config/testthat/start-first: aaa
SystemRequirements: OpenSSL >= 1.0.1
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ loadvals <- function(sheet_data, doc) {
invisible(.Call(`_openxlsx2_loadvals`, sheet_data, doc))
}

msoc <- function(mode, inFile, outFile, pass) {
.Call(`_openxlsx2_msoc`, mode, inFile, outFile, pass)
}

readXMLPtr <- function(path, isfile, escapes, declaration, whitespace, empty_tags, skip_control) {
.Call(`_openxlsx2_readXMLPtr`, path, isfile, escapes, declaration, whitespace, empty_tags, skip_control)
}
Expand Down
105 changes: 105 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Anticonf (tm) script by Jeroen Ooms (2020)
# This script will query 'pkg-config' for the required cflags and ldflags.
# If pkg-config is unavailable or does not find the library, try setting
# INCLUDE_DIR and LIB_DIR manually via e.g:
# R CMD INSTALL --configure-vars='INCLUDE_DIR=/.../include LIB_DIR=/.../lib'

# Library settings
PKG_CONFIG_NAME="openssl"
PKG_DEB_NAME="libssl-dev"
PKG_RPM_NAME="openssl-devel"
PKG_CSW_NAME="libssl_dev"
PKG_BREW_NAME="openssl"
PKG_TEST_FILE="tools/version.c"
PKG_LIBS="-lssl -lcrypto"
PKG_CFLAGS=""

# Build against a specific openssl version
# export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

# Use pkg-config if available
pkg-config ${PKG_CONFIG_NAME} --atleast-version=1.0 2>/dev/null
if [ $? -eq 0 ]; then
PKGCONFIG_CFLAGS=`pkg-config --cflags ${PKG_CONFIG_NAME}`
PKGCONFIG_LIBS=`pkg-config --libs ${PKG_CONFIG_NAME}`
fi

# Note that cflags may be empty in case of success
if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then
echo "Found INCLUDE_DIR and/or LIB_DIR!"
PKG_CFLAGS="-I$INCLUDE_DIR $PKG_CFLAGS"
PKG_LIBS="-L$LIB_DIR $PKG_LIBS"
elif [ "$PKGCONFIG_CFLAGS" ] || [ "$PKGCONFIG_LIBS" ]; then
echo "Found pkg-config cflags and libs!"
PKG_CFLAGS=${PKGCONFIG_CFLAGS}
PKG_LIBS=${PKGCONFIG_LIBS}
elif [ `uname` = "Darwin" ]; then
test ! "$CI" && brew --version 2>/dev/null
if [ $? -eq 0 ]; then
BREWDIR=`brew --prefix`
PKG_CFLAGS="-I$BREWDIR/opt/openssl/include -I$BREWDIR/opt/openssl@1.1/include"
PKG_LIBS="-L$BREWDIR/opt/openssl/lib -L$BREWDIR/opt/openssl@1.1/lib $PKG_LIBS"
else
curl -sfL "https://autobrew.github.io/scripts/$PKG_BREW_NAME" > autobrew
. ./autobrew
fi
fi

# Find compiler
CC=`${R_HOME}/bin/R CMD config CC`
CFLAGS=`${R_HOME}/bin/R CMD config CFLAGS`
CPPFLAGS=`${R_HOME}/bin/R CMD config CPPFLAGS`

# For debugging
echo "Using PKG_CFLAGS=$PKG_CFLAGS"

# Test configuration
${CC} ${CPPFLAGS} ${PKG_CFLAGS} ${CFLAGS} -E ${PKG_TEST_FILE} >/dev/null 2>configure.log

# Customize the error
if [ $? -ne 0 ]; then
echo "--------------------------- [ANTICONF] --------------------------------"
echo "Configuration failed because $PKG_CONFIG_NAME was not found. Try installing:"
echo " * deb: $PKG_DEB_NAME (Debian, Ubuntu, etc)"
echo " * rpm: $PKG_RPM_NAME (Fedora, CentOS, RHEL)"
echo " * csw: $PKG_CSW_NAME (Solaris)"
echo " * brew: $PKG_BREW_NAME (Mac OSX)"
echo "If $PKG_CONFIG_NAME is already installed, check that 'pkg-config' is in your"
echo "PATH and PKG_CONFIG_PATH contains a $PKG_CONFIG_NAME.pc file. If pkg-config"
echo "is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:"
echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'"
echo "-------------------------- [ERROR MESSAGE] ---------------------------"
cat configure.log
echo "--------------------------------------------------------------------"
exit 1
fi

# Try to link against the correct OpenSSL version
if [ -z "$AUTOBREW" ]; then
SONAME=`${CC} -E ${PKG_CFLAGS} src/tests/soname.h | sh | xargs`
if [ "$SONAME" ]; then
if [ `uname` = "Darwin" ]; then
PKG_LIBS_VERSIONED=`echo "${PKG_LIBS}" | sed "s/-lssl/-lssl.${SONAME}/" | sed "s/-lcrypto/-lcrypto.${SONAME}/"`
else
PKG_LIBS_VERSIONED=`echo "${PKG_LIBS}" | sed "s/-lssl/-l:libssl.so.${SONAME}/" | sed "s/-lcrypto/-l:libcrypto.so.${SONAME}/"`
fi

# Test if versioned linking works
${CC} ${PKG_CFLAGS} src/tests/main.c ${PKG_LIBS_VERSIONED} -o src/main.exe 2>/dev/null
if [ $? -eq 0 ]; then PKG_LIBS="${PKG_LIBS_VERSIONED}"; fi

# Suppress opensslv3 warnings for now
if [ "$SONAME" = "3" ]; then
PKG_CFLAGS="$PKG_CFLAGS -DOPENSSL_SUPPRESS_DEPRECATED"
fi

fi #SONAME
fi #AUTOBREW

echo "Using PKG_LIBS=$PKG_LIBS"

# Write to Makevars
sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars

# Success
exit 0
Empty file added configure.log
Empty file.
1 change: 0 additions & 1 deletion src/Makevars

This file was deleted.

17 changes: 17 additions & 0 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PKG_CPPFLAGS = @cflags@ -I. -I../inst/include/pugixml -Icryptography -Icryptography/msoc/include
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` @libs@

OBJECTS = cryptography/msoc/msocdll.o \
helper_functions.o \
load_workbook.o \
msoc.o \
pugi.o \
strings_xml.o \
styles_xml.o \
write_file.o \
RcppExports.o

all: clean

clean:
rm -f $(OBJECTS) $(SHLIB)
2 changes: 2 additions & 0 deletions src/Makevars.ucrt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CRT=-ucrt
include Makevars.win
21 changes: 21 additions & 0 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
VERSION=1.1.1k
PKG_CPPFLAGS= -I../windows/openssl-$(VERSION)/include -I. -I../inst/include/pugixml -Icryptography -Icryptography/msoc/include
PKG_LIBS = -L../windows/openssl-$(VERSION)/lib${R_ARCH}${CRT} -lcrypto -lws2_32 -lcrypt32 -fPIC

OBJECTS = cryptography/msoc/msocdll.o \
helper_functions.o \
load_workbook.o \
msoc.o \
pugi.o \
strings_xml.o \
styles_xml.o \
write_file.o \
RcppExports.o

all: clean winlibs

clean:
rm -f $(SHLIB) $(OBJECTS)

winlibs:
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" $(VERSION)
15 changes: 15 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ BEGIN_RCPP
return R_NilValue;
END_RCPP
}
// msoc
int msoc(std::string mode, std::string inFile, std::string outFile, std::string pass);
RcppExport SEXP _openxlsx2_msoc(SEXP modeSEXP, SEXP inFileSEXP, SEXP outFileSEXP, SEXP passSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type mode(modeSEXP);
Rcpp::traits::input_parameter< std::string >::type inFile(inFileSEXP);
Rcpp::traits::input_parameter< std::string >::type outFile(outFileSEXP);
Rcpp::traits::input_parameter< std::string >::type pass(passSEXP);
rcpp_result_gen = Rcpp::wrap(msoc(mode, inFile, outFile, pass));
return rcpp_result_gen;
END_RCPP
}
// readXMLPtr
SEXP readXMLPtr(std::string path, bool isfile, bool escapes, bool declaration, bool whitespace, bool empty_tags, bool skip_control);
RcppExport SEXP _openxlsx2_readXMLPtr(SEXP pathSEXP, SEXP isfileSEXP, SEXP escapesSEXP, SEXP declarationSEXP, SEXP whitespaceSEXP, SEXP empty_tagsSEXP, SEXP skip_controlSEXP) {
Expand Down Expand Up @@ -855,6 +869,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_openxlsx2_col_to_df", (DL_FUNC) &_openxlsx2_col_to_df, 1},
{"_openxlsx2_df_to_xml", (DL_FUNC) &_openxlsx2_df_to_xml, 2},
{"_openxlsx2_loadvals", (DL_FUNC) &_openxlsx2_loadvals, 2},
{"_openxlsx2_msoc", (DL_FUNC) &_openxlsx2_msoc, 4},
{"_openxlsx2_readXMLPtr", (DL_FUNC) &_openxlsx2_readXMLPtr, 7},
{"_openxlsx2_readXML", (DL_FUNC) &_openxlsx2_readXML, 7},
{"_openxlsx2_is_xml", (DL_FUNC) &_openxlsx2_is_xml, 1},
Expand Down
27 changes: 27 additions & 0 deletions src/cryptography/cybozu/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Copyright (c) 2007-2012 Cybozu Labs, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the name of the Cybozu Labs, Inc. nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit f2346fe

Please sign in to comment.