Skip to content

Commit

Permalink
Merge pull request #8 from muflihun/develop
Browse files Browse the repository at this point in the history
static linking
  • Loading branch information
abumq authored Jan 9, 2018
2 parents ec84272 + 96019cd commit 74124cc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 124 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.0.2] - 09-01-2018
### Updates
- Removed unnecessary zlib dependency

## [1.0.1] - 09-01-2018
### Updates
- Docs update
Expand Down
15 changes: 3 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set (LICENSEPP_SOVERSION "${LICENSEPP_MAJOR}.${LICENSEPP_MINOR}.${LICENSEPP_PATC
set (LICENSEPP_NAME "licensepp")

add_definitions (-DLICENSEPP_SOVERSION="${LICENSEPP_SOVERSION}")
add_definitions (-DRIPE_VERSION="4.0.1-static")
add_definitions (-DRIPE_VERSION="4.0.1-custom-static")
if (travis)
add_definitions (-DLICENSEPP_ON_CI)
endif()
Expand All @@ -35,15 +35,7 @@ if (APPLE)
endif()
endif()

list (APPEND CMAKE_CXX_FLAGS " -std=c++11 -O3 -Wall -Werror -Wno-unknown-warning-option -Wno-pessimizing-move ")

find_package(ZLIB REQUIRED)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
message ("-- libz: " ${ZLIB_LIBRARIES} " version: " ${ZLIB_VERSION_STRING})
else()
message ("--==> libz not found")
endif(ZLIB_FOUND)
list (APPEND CMAKE_CXX_FLAGS " -std=c++11 -O3 -Wall -Werror ")

# Check for cryptopp (static)
set(CryptoPP_USE_STATIC_LIBS ON)
Expand Down Expand Up @@ -78,7 +70,6 @@ set_target_properties (licensepp-lib PROPERTIES
VERSION ${LICENSEPP_SOVERSION}
)
target_link_libraries (licensepp-lib
${ZLIB_LIBRARIES}
${CRYPTOPP_LIBRARIES}
)

Expand Down Expand Up @@ -133,7 +124,7 @@ if (test)
# Extra linking for the project.
target_link_libraries (licensepp-unit-tests licensepp)

target_link_libraries (licensepp-unit-tests ${SHARED_REQUIRED_LIBS})
target_link_libraries (licensepp-unit-tests ${CRYPTOPP_LIBRARIES})

add_test (NAME licenseppUnitTests COMMAND licensepp-unit-tests)
endif() ## test
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ License++ is software licensing library that provides an abstract way to secure
* C++11
* [Crypto++](https://www.cryptopp.com/) v5.6.5+ [with Pem Pack](https://raw.githubusercontent.com/muflihun/muflihun.github.io/master/downloads/pem_pack.zip)
* [cmake](https://cmake.org/) v2.8.12+
* [zlib-devel](https://zlib.net/)

### Installation
* [Download](https://github.com/muflihun/licensepp/archive/master.zip) or [clone]([email protected]:muflihun/licensepp.git) the repository
Expand All @@ -48,6 +47,11 @@ License++ is software licensing library that provides an abstract way to secure
cd build
cmake ..
make install
## build with test
cmake -Dtest=ON ..
make install
./licensepp-unit-tests
```
* You can build [cli](/cli) tool to ensure license++ is installed properly
Expand Down
113 changes: 3 additions & 110 deletions src/external/Ripe.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//
// Ripe.cc
//
// Copyright (c) 2017, Muflihun Labs
// Copyright (c) 2017-present Muflihun Labs
//
// https://muflihun.com
// https://muflihun.github.io/ripe
// https://github.com/muflihun
//
// [This is custom version of Ripe for License++]
//

#include <cerrno>
#include <iomanip>
Expand All @@ -25,8 +27,6 @@
#include <cryptopp/pem.h>
#include <cryptopp/rsa.h>

#include <zlib.h>

#include "src/external/Ripe.h"

#define RIPE_UNUSED(x) (void)x
Expand Down Expand Up @@ -386,113 +386,6 @@ std::string Ripe::decryptAES(std::string& data, const std::string& hexKey, std::
return Ripe::decryptAES(data, reinterpret_cast<const RipeByte*>(Ripe::hexToString(hexKey).c_str()), hexKey.size() / 2, ivHex);
}

bool Ripe::compressFile(const std::string& gzFilename, const std::string& inputFile)
{
gzFile out = gzopen(gzFilename.c_str(), "wb");
if (!out) {
throw std::runtime_error(
std::string("Unable to open file for writing [" + gzFilename + "] " + std::strerror(errno)).data()
);
return false;
}
char buff[BUFSIZ];
std::FILE* in = std::fopen(inputFile.c_str(), "rb");
std::size_t nRead = 0;
while((nRead = std::fread(buff, sizeof(char), BUFSIZ, in)) > 0) {
int RipeBytes_written = gzwrite(out, buff, nRead);
if (RipeBytes_written == 0) {
int err_no = 0;
throw std::runtime_error(
std::string("Error during compression " + std::string(gzerror(out, &err_no))).data()
);
gzclose(out);
return false;
}
}
gzclose(out);
std::fclose(in);
return true;
}

std::string Ripe::compressString(const std::string& str)
{
int compressionlevel = Z_BEST_COMPRESSION;
z_stream zs;
memset(&zs, 0, sizeof(zs));

if (deflateInit(&zs, compressionlevel) != Z_OK) {
throw std::runtime_error("Unable to initialize zlib deflate");
}

zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(str.data()));
zs.avail_in = str.size();

int ret;
char outbuffer[ZLIB_BUFFER_SIZE];
std::string outstring;

// retrieve the compressed RipeBytes blockwise
do {
zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
zs.avail_out = sizeof(outbuffer);

ret = deflate(&zs, Z_FINISH);

if (outstring.size() < zs.total_out) {
outstring.append(outbuffer, zs.total_out - outstring.size());
}
} while (ret == Z_OK);

deflateEnd(&zs);

if (ret != Z_STREAM_END) {
std::ostringstream oss;
oss << "Exception during zlib compression: (" << ret << ") " << zs.msg;
throw std::runtime_error(oss.str());
}

return outstring;
}

std::string Ripe::decompressString(const std::string& str)
{
z_stream zs;
memset(&zs, 0, sizeof(zs));

if (inflateInit(&zs) != Z_OK) {
throw std::runtime_error("Unable to initialize zlib inflate");
}

zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(str.data()));
zs.avail_in = str.size();

int ret;
char outbuffer[ZLIB_BUFFER_SIZE];
std::string outstring;

do {
zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
zs.avail_out = sizeof(outbuffer);

ret = inflate(&zs, 0);

if (outstring.size() < zs.total_out) {
outstring.append(outbuffer, zs.total_out - outstring.size());
}

} while (ret == Z_OK);

inflateEnd(&zs);

if (ret != Z_STREAM_END) {
std::ostringstream oss;
oss << "Exception during zlib decompression: (" << ret << ") " << zs.msg;
throw std::runtime_error(oss.str());
}

return outstring;
}

std::string Ripe::prepareData(const std::string& data, const std::string& hexKey, const char* clientId, const std::string& ivec)
{
std::vector<RipeByte> iv;
Expand Down
4 changes: 3 additions & 1 deletion src/external/Ripe.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//
// Ripe.cc
//
// Copyright (c) 2017, Muflihun Labs
// Copyright (c) 2017-present, Muflihun Labs
//
// https://muflihun.com
// https://muflihun.github.io/ripe
// https://github.com/muflihun
//
// [This is custom version of Ripe for License++]
//

#ifndef Ripe_h
#define Ripe_h
Expand Down

0 comments on commit 74124cc

Please sign in to comment.