Skip to content
Merged
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
13 changes: 6 additions & 7 deletions cdoc/CDoc1Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ struct CDoc1Writer::Private final: public XMLWriter
std::string documentFormat = "ENCDOC-XML|1.1";
std::string &lastError;
std::vector<FileEntry> files;
std::vector<Recipient> rcpts;

int64_t writeEncryptionProperties(bool use_ddoc);
int64_t writeKeyInfo(bool use_ddoc, const std::vector<Recipient> &rcpts, const Crypto::Key& transportKey);
Expand Down Expand Up @@ -233,7 +232,7 @@ CDoc1Writer::encrypt(libcdoc::MultiDataSource& src, const std::vector<libcdoc::R
if(keys.empty())
return WORKFLOW_ERROR;
RET_ERROR(beginEncryption());
d->rcpts = keys;
rcpts = keys;
Crypto::Key transportKey = Crypto::generateKey(d->method);
int n_components = src.getNumComponents();
bool use_ddoc = (n_components > 1) || (n_components == libcdoc::NOT_IMPLEMENTED);
Expand Down Expand Up @@ -272,7 +271,7 @@ CDoc1Writer::encrypt(libcdoc::MultiDataSource& src, const std::vector<libcdoc::R
libcdoc::result_t
CDoc1Writer::beginEncryption()
{
if(!dst)
if(d)
return WORKFLOW_ERROR;
d = std::make_unique<Private>(*dst, last_error);
return libcdoc::OK;
Expand All @@ -281,9 +280,9 @@ CDoc1Writer::beginEncryption()
libcdoc::result_t
CDoc1Writer::addRecipient(const libcdoc::Recipient& rcpt)
{
if(!d)
if(d)
return WORKFLOW_ERROR;
d->rcpts.push_back(rcpt);
rcpts.push_back(rcpt);
return libcdoc::OK;
}

Expand All @@ -309,12 +308,12 @@ CDoc1Writer::writeData(const uint8_t *src, size_t size)
libcdoc::result_t
CDoc1Writer::finishEncryption()
{
if(!d || d->rcpts.empty() || d->files.empty())
if(!d || rcpts.empty() || d->files.empty())
return WORKFLOW_ERROR;
bool use_ddoc = d->files.size() > 1;
libcdoc::Crypto::Key transportKey = libcdoc::Crypto::generateKey(d->method);

RET_ERROR(d->writeKeyInfo(use_ddoc, d->rcpts, transportKey));
RET_ERROR(d->writeKeyInfo(use_ddoc, rcpts, transportKey));
RET_ERROR(d->writeElement(Private::DENC, "CipherData", [&] {
return d->writeBase64Element(Private::DENC, "CipherValue", [&](DataConsumer &dst) -> int64_t {
EncryptionConsumer enc(dst, d->method, transportKey);
Expand Down
1 change: 1 addition & 0 deletions cdoc/CDoc1Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CDoc1Writer final: public libcdoc::CDocWriter

private:
CDOC_DISABLE_COPY(CDoc1Writer)
std::vector<libcdoc::Recipient> rcpts;
struct Private;
std::unique_ptr<Private> d;
};
6 changes: 2 additions & 4 deletions cdoc/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "json/jwt.h"
#include "json/picojson/picojson.h"

#define OPENSSL_SUPPRESS_DEPRECATED

#include <openssl/evp.h>
#include <openssl/http.h>

Expand Down Expand Up @@ -60,9 +58,9 @@ getTime()
#endif

double
timeFromISO(std::string_view iso)
timeFromISO(const std::string& iso)
{
std::istringstream in{std::string(iso.data(), iso.size())};
std::istringstream in{iso};
std::tm t = {};
in >> std::get_time(&t, "%Y-%m-%dT%TZ");
return timegm(&t);
Expand Down
2 changes: 1 addition & 1 deletion cdoc/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ std::vector<std::string> JsonToStringArray(std::string_view json);
// Get time in seconds since the Epoch

double getTime();
double timeFromISO(std::string_view iso);
double timeFromISO(const std::string& iso);
std::string timeToISO(double time);

bool isValidUtf8 (std::string str);
Expand Down
Loading