Skip to content

Commit 847747c

Browse files
committed
MOPP
1 parent 9d9b30a commit 847747c

File tree

9 files changed

+61
-4
lines changed

9 files changed

+61
-4
lines changed

cdoc/CDoc1Reader.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,24 @@ CDoc1Reader::decrypt(const std::vector<uint8_t>& fmk, libcdoc::MultiDataConsumer
209209
int
210210
CDoc1Reader::beginDecryption(const std::vector<uint8_t>& fmk)
211211
{
212+
if (fmk.empty()) {
213+
setLastError("FMK is missing");
214+
return libcdoc::WORKFLOW_ERROR;
215+
}
216+
if (fmk.size() != 16 && fmk.size() != 24 && fmk.size() != 32) {
217+
setLastError("FMK must be AES key with size 128, 192,2 56 bits");
218+
return libcdoc::WORKFLOW_ERROR;
219+
}
212220
if (!d->files.empty() || (d->f_pos != -1)) {
213221
setLastError("Container is already parsed");
214222
return libcdoc::WORKFLOW_ERROR;
215223
}
216224
std::vector<uint8_t> data = this->decryptData(fmk);
225+
if(data.empty()) {
226+
setLastError("Failed to decrypt data, verify if FMK is correct");
227+
return libcdoc::WORKFLOW_ERROR;
228+
}
229+
217230
std::string mime = d->mime;
218231
if (d->mime == MIME_ZLIB) {
219232
libcdoc::VectorSource vsrc(data);

cdoc/CDoc1Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ int
270270
CDoc1Writer::addFile(const std::string& name, size_t size)
271271
{
272272
d->files.push_back({name, size, {}});
273-
return libcdoc::NOT_IMPLEMENTED;
273+
return libcdoc::OK;
274274
}
275275

276276
int64_t

cdoc/CDocChipher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ void CDocChipher::Locks(const char* file) const
448448
}
449449
}
450450

451-
#if defined(_WIN32) || defined(_WIN64) || defined(__GNUC__)
451+
#if defined(_WIN32) || defined(_WIN64) || !defined(__APPLE__)
452452
uint32_t
453453
arc4random_uniform(uint32_t upperbound)
454454
{

cdoc/CDocReader.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,20 @@ class CDOC_EXPORT CDocReader {
165165
*/
166166
static CDocReader *createReader(const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network);
167167

168+
static CDocReader *createReader(const std::string& path, CryptoBackend *crypto) {
169+
return createReader(path, nullptr, crypto, nullptr);
170+
}
171+
168172
#if LIBCDOC_TESTING
169173
virtual int64_t testConfig(std::vector<uint8_t>& dst);
170174
virtual int64_t testNetwork(std::vector<std::vector<uint8_t>>& dst);
171175
#endif
172176
protected:
173177
explicit CDocReader(int _version) : version(_version) {};
178+
CDocReader (const CDocReader&) = delete;
179+
CDocReader (CDocReader&&) noexcept;
180+
CDocReader& operator= (const CDocReader&) = delete;
181+
CDocReader& operator= (CDocReader&&) noexcept;
174182

175183
void setLastError(const std::string& message) { last_error = message; }
176184

cdoc/CDocWriter.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@
2828
#include <cdoc/Exports.h>
2929
#include <cdoc/NetworkBackend.h>
3030

31+
#if __has_include(<swift/bridging>)
32+
#include <swift/bridging>
33+
#endif
34+
#ifndef SWIFT_NONCOPYABLE
35+
#define SWIFT_NONCOPYABLE
36+
#endif
37+
3138
namespace libcdoc {
3239

33-
class CDOC_EXPORT CDocWriter {
40+
class CDOC_EXPORT SWIFT_NONCOPYABLE CDocWriter {
3441
public:
3542
virtual ~CDocWriter();
3643

@@ -106,6 +113,10 @@ class CDOC_EXPORT CDocWriter {
106113
static CDocWriter *createWriter(int version, const std::string& path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network);
107114
protected:
108115
explicit CDocWriter(int _version, DataConsumer *dst, bool take_ownership);
116+
CDocWriter (const CDocWriter&) = delete;
117+
CDocWriter (CDocWriter&&) noexcept;
118+
CDocWriter& operator= (const CDocWriter&) = delete;
119+
CDocWriter& operator= (CDocWriter&&) noexcept;
109120

110121
void setLastError(const std::string& message) { last_error = message; }
111122

cdoc/CryptoBackend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ struct CDOC_EXPORT CryptoBackend {
151151
virtual int test(libcdoc::Lock& lock) { return NOT_IMPLEMENTED; }
152152

153153
CryptoBackend (const CryptoBackend&) = delete;
154+
CryptoBackend (CryptoBackend&&) noexcept = default;
154155
CryptoBackend& operator= (const CryptoBackend&) = delete;
156+
CryptoBackend& operator= (CryptoBackend&&) noexcept = default;
155157
};
156158

157159
} // namespace libcdoc

cdoc/Io.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,30 @@
66
#include <cdoc/CDoc.h>
77

88
#include <cstdint>
9-
#include <filesystem>
109
#include <fstream>
1110
#include <iostream>
1211
#include <vector>
1312

13+
#ifdef __swift__
14+
// Swift compiler can't handle std::filesystem; provide a stub
15+
namespace std {
16+
namespace filesystem {
17+
class path {
18+
std::string p;
19+
public:
20+
path(std::string str = {}) : p(std::move(str)) {}
21+
std::string string() const { return p; }
22+
inline path& operator/=(const path &other) {
23+
p += "/" + other.p;
24+
return *this;
25+
}
26+
};
27+
}
28+
}
29+
#else
30+
#include <filesystem>
31+
#endif
32+
1433
namespace libcdoc {
1534

1635
class DataSource;

cdoc/Lock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ struct CDOC_EXPORT Lock
104104
void setString(Params key, const std::string& val) { params[key] = std::vector<uint8_t>(val.cbegin(), val.cend()); }
105105
void setInt(Params key, int32_t val);
106106

107+
#ifndef __swift__
107108
bool operator== (const Lock& other) const = default;
109+
#endif
108110

109111
// Set certificate, rcpt_key and pk_type values
110112
void setCertificate(const std::vector<uint8_t>& cert);

cdoc/Recipient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ struct CDOC_EXPORT Recipient {
9494

9595
static std::map<std::string, std::string> parseLabel(const std::string& label);
9696

97+
#ifndef __swift__
9798
bool operator== (const Recipient& other) const = default;
99+
#endif
98100
protected:
99101
Recipient(Type _type) : type(_type) {};
100102
private:

0 commit comments

Comments
 (0)