Skip to content

Commit 2ee27ed

Browse files
authored
Various cleanups (#73)
Signed-off-by: Raul Metsma <[email protected]>
1 parent 86b154a commit 2ee27ed

File tree

14 files changed

+46
-124
lines changed

14 files changed

+46
-124
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ jobs:
6969
- name: Prepare vcpkg
7070
uses: lukka/run-vcpkg@v11
7171
with:
72-
vcpkgGitCommitId: 085820b35f4ef5ad54967c8a46fb822e53c4be33
7372
vcpkgJsonGlob: ./vcpkg.json
7473
runVcpkgInstall: true
7574
env:
@@ -116,7 +115,6 @@ jobs:
116115
if: matrix.target != 'macos'
117116
uses: lukka/run-vcpkg@v11
118117
with:
119-
vcpkgGitCommitId: 085820b35f4ef5ad54967c8a46fb822e53c4be33
120118
vcpkgJsonGlob: ./vcpkg.json
121119
runVcpkgInstall: true
122120
env:
@@ -158,7 +156,6 @@ jobs:
158156
- name: Prepare vcpkg
159157
uses: lukka/run-vcpkg@v11
160158
with:
161-
vcpkgGitCommitId: 085820b35f4ef5ad54967c8a46fb822e53c4be33
162159
vcpkgJsonGlob: ./vcpkg.json
163160
runVcpkgInstall: true
164161
runVcpkgFormatString: "[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`, `--x-feature`, `tests`]"

CMakePresets.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"cacheVariables": {
3030
"CMAKE_OSX_ARCHITECTURES": "arm64",
31-
"CMAKE_OSX_DEPLOYMENT_TARGET": "12.0",
31+
"CMAKE_OSX_DEPLOYMENT_TARGET": "13.3",
3232
"CMAKE_FIND_ROOT_PATH": "$env{DEST};/opt/homebrew",
3333
"FRAMEWORK_DESTINATION": "$env{DEST}/lib"
3434
},
@@ -56,7 +56,8 @@
5656
"CMAKE_SYSTEM_NAME": "iOS",
5757
"CMAKE_OSX_SYSROOT": "${presetName}",
5858
"CMAKE_OSX_DEPLOYMENT_TARGET": "15.0",
59-
"CMAKE_DISABLE_FIND_PACKAGE_SWIG": "YES"
59+
"CMAKE_DISABLE_FIND_PACKAGE_SWIG": "YES",
60+
"CMAKE_CXX_FLAGS": "-D_LIBCPP_DISABLE_AVAILABILITY"
6061
}
6162
},
6263
{
@@ -140,4 +141,4 @@
140141
"configurePreset": "androidx86_64"
141142
}
142143
]
143-
}
144+
}

cdoc/CDoc.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ libcdoc::CDocReader::getCDocFileVersion(const std::string& path)
9898
libcdoc::CDocReader *
9999
libcdoc::CDocReader::createReader(DataSource *src, bool take_ownership, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network)
100100
{
101+
if(!src)
102+
return nullptr;
101103
int version = getCDocFileVersion(src);
102104
LOG_DBG("CDocReader::createReader: version {}", version);
103105
if (src->seek(0) != libcdoc::OK) return nullptr;
@@ -106,7 +108,9 @@ libcdoc::CDocReader::createReader(DataSource *src, bool take_ownership, Configur
106108
reader = new CDoc1Reader(src, take_ownership);
107109
} else if (version == 2) {
108110
reader = new CDoc2Reader(src, take_ownership);
109-
} else {
111+
} else {
112+
if(take_ownership)
113+
delete src;
110114
return nullptr;
111115
}
112116
reader->conf = conf;
@@ -118,12 +122,18 @@ libcdoc::CDocReader::createReader(DataSource *src, bool take_ownership, Configur
118122
libcdoc::CDocReader *
119123
libcdoc::CDocReader::createReader(const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network)
120124
{
121-
int version = getCDocFileVersion(path);
125+
if(path.empty())
126+
return nullptr;
127+
auto isrc = make_unique<IStreamSource>(path);
128+
int version = getCDocFileVersion(isrc.get());
129+
LOG_DBG("CDocReader::createReader: version {}", version);
130+
if (isrc->seek(0) != libcdoc::OK)
131+
return nullptr;
122132
CDocReader *reader;
123133
if (version == 1) {
124-
reader = new CDoc1Reader(path);
134+
reader = new CDoc1Reader(isrc.release(), true);
125135
} else if (version == 2) {
126-
reader = new CDoc2Reader(path);
136+
reader = new CDoc2Reader(isrc.release(), true);
127137
} else {
128138
return nullptr;
129139
}
@@ -138,6 +148,7 @@ libcdoc::CDocReader::createReader(std::istream& ifs, Configuration *conf, Crypto
138148
{
139149
libcdoc::IStreamSource *isrc = new libcdoc::IStreamSource(&ifs, false);
140150
int version = getCDocFileVersion(isrc);
151+
LOG_DBG("CDocReader::createReader: version {}", version);
141152
CDocReader *reader;
142153
if (version == 1) {
143154
reader = new CDoc1Reader(isrc, true);

cdoc/CDoc1Reader.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,6 @@ CDoc1Reader::~CDoc1Reader()
340340
delete d;
341341
}
342342

343-
CDoc1Reader::CDoc1Reader(const std::string &path)
344-
: CDoc1Reader(new libcdoc::IStreamSource(path), true)
345-
{
346-
}
347-
348343
bool
349344
CDoc1Reader::isCDoc1File(libcdoc::DataSource *src)
350345
{

cdoc/CDoc1Reader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class CDoc1Reader : public libcdoc::CDocReader
2626
{
2727
public:
2828
CDoc1Reader(libcdoc::DataSource *src, bool take_ownership = false);
29-
CDoc1Reader(const std::string& path);
3029
~CDoc1Reader();
3130

3231
const std::vector<libcdoc::Lock>& getLocks() override final;

cdoc/CDoc2Reader.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -677,21 +677,15 @@ CDoc2Reader::CDoc2Reader(libcdoc::DataSource *src, bool take_ownership)
677677
}
678678
}
679679

680-
CDoc2Reader::CDoc2Reader(const std::string &path)
681-
: CDoc2Reader(new libcdoc::IStreamSource(path), true)
682-
{
683-
}
684-
685680
bool
686681
CDoc2Reader::isCDoc2File(libcdoc::DataSource *src)
687682
{
688-
uint8_t in[libcdoc::CDoc2::LABEL.size()];
689-
constexpr size_t len = libcdoc::CDoc2::LABEL.size();
690-
if (src->read(&in[0], len) != len) {
691-
LOG_DBG("CDoc2Reader::isCDoc1File: Cannot read tag");
683+
std::array<uint8_t,libcdoc::CDoc2::LABEL.size()> in {};
684+
if (src->read(in.data(), in.size()) != in.size()) {
685+
LOG_DBG("CDoc2Reader::isCDoc2File: Cannot read tag");
692686
return false;
693687
}
694-
if (libcdoc::CDoc2::LABEL.compare(0, len, (char *) &in[0], len)) {
688+
if (libcdoc::CDoc2::LABEL.compare(0, in.size(), (char *) in.data(), in.size())) {
695689
LOG_DBG("CDoc2Reader::isCDoc2File: Invalid tag: {}", toHex(in));
696690
return false;
697691
}

cdoc/CDoc2Reader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class CDoc2Reader final: public libcdoc::CDocReader {
3939
libcdoc::result_t finishDecryption() override final;
4040

4141
CDoc2Reader(libcdoc::DataSource *src, bool take_ownership = false);
42-
CDoc2Reader(const std::string &path);
4342

4443
static bool isCDoc2File(const std::string& path);
4544
static bool isCDoc2File(libcdoc::DataSource *src);

cdoc/CDocReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ class CDOC_EXPORT CDocReader {
165165
*
166166
* Creates a new document reader if source is a valid CDoc container (either version 1 or 2).
167167
* Configuration and NetworkBackend may be null if keyservers are not used.
168+
* If take_ownership is true, the source is deleted by the reader destructor. If src is not a valid CDoc file,
169+
* the source is deleted before returning null.
168170
* @param src the container source
169171
* @param take_ownership if true the source is deleted in reader destructor
170172
* @param conf a configuration object

cdoc/Crypto.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

2424
#define OPENSSL_SUPPRESS_DEPRECATED
2525

26+
#ifdef _WIN32
27+
#include <windows.h> // For RAND_screen
28+
#endif
29+
2630
#include <openssl/aes.h>
2731
#include <openssl/err.h>
2832
#include <openssl/kdf.h>

cdoc/PKCS11Backend.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
#include <functional>
3838

3939
#ifdef _WIN32
40-
//#include <Windows.h>
41-
//#include <wincrypt.h>
42-
//#include <cryptuiapi.h>
40+
#include <Windows.h>
4341
#else
4442
#include <dlfcn.h>
4543
#endif

0 commit comments

Comments
 (0)