Skip to content

Commit 2c70edb

Browse files
authored
Fix workflow order with CDoc1 (#82)
Signed-off-by: Raul Metsma <[email protected]>
1 parent 321fd87 commit 2c70edb

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

cdoc/CDoc1Writer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ struct CDoc1Writer::Private final: public XMLWriter
5656
std::string documentFormat = "ENCDOC-XML|1.1";
5757
std::string &lastError;
5858
std::vector<FileEntry> files;
59-
std::vector<Recipient> rcpts;
6059

6160
int64_t writeEncryptionProperties(bool use_ddoc);
6261
int64_t writeKeyInfo(bool use_ddoc, const std::vector<Recipient> &rcpts, const Crypto::Key& transportKey);
@@ -233,7 +232,7 @@ CDoc1Writer::encrypt(libcdoc::MultiDataSource& src, const std::vector<libcdoc::R
233232
if(keys.empty())
234233
return WORKFLOW_ERROR;
235234
RET_ERROR(beginEncryption());
236-
d->rcpts = keys;
235+
rcpts = keys;
237236
Crypto::Key transportKey = Crypto::generateKey(d->method);
238237
int n_components = src.getNumComponents();
239238
bool use_ddoc = (n_components > 1) || (n_components == libcdoc::NOT_IMPLEMENTED);
@@ -272,7 +271,7 @@ CDoc1Writer::encrypt(libcdoc::MultiDataSource& src, const std::vector<libcdoc::R
272271
libcdoc::result_t
273272
CDoc1Writer::beginEncryption()
274273
{
275-
if(!dst)
274+
if(d)
276275
return WORKFLOW_ERROR;
277276
d = std::make_unique<Private>(*dst, last_error);
278277
return libcdoc::OK;
@@ -281,9 +280,9 @@ CDoc1Writer::beginEncryption()
281280
libcdoc::result_t
282281
CDoc1Writer::addRecipient(const libcdoc::Recipient& rcpt)
283282
{
284-
if(!d)
283+
if(d)
285284
return WORKFLOW_ERROR;
286-
d->rcpts.push_back(rcpt);
285+
rcpts.push_back(rcpt);
287286
return libcdoc::OK;
288287
}
289288

@@ -309,12 +308,12 @@ CDoc1Writer::writeData(const uint8_t *src, size_t size)
309308
libcdoc::result_t
310309
CDoc1Writer::finishEncryption()
311310
{
312-
if(!d || d->rcpts.empty() || d->files.empty())
311+
if(!d || rcpts.empty() || d->files.empty())
313312
return WORKFLOW_ERROR;
314313
bool use_ddoc = d->files.size() > 1;
315314
libcdoc::Crypto::Key transportKey = libcdoc::Crypto::generateKey(d->method);
316315

317-
RET_ERROR(d->writeKeyInfo(use_ddoc, d->rcpts, transportKey));
316+
RET_ERROR(d->writeKeyInfo(use_ddoc, rcpts, transportKey));
318317
RET_ERROR(d->writeElement(Private::DENC, "CipherData", [&] {
319318
return d->writeBase64Element(Private::DENC, "CipherValue", [&](DataConsumer &dst) -> int64_t {
320319
EncryptionConsumer enc(dst, d->method, transportKey);

cdoc/CDoc1Writer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CDoc1Writer final: public libcdoc::CDocWriter
3838

3939
private:
4040
CDOC_DISABLE_COPY(CDoc1Writer)
41+
std::vector<libcdoc::Recipient> rcpts;
4142
struct Private;
4243
std::unique_ptr<Private> d;
4344
};

cdoc/Utils.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include "json/jwt.h"
2424
#include "json/picojson/picojson.h"
2525

26-
#define OPENSSL_SUPPRESS_DEPRECATED
27-
2826
#include <openssl/evp.h>
2927
#include <openssl/http.h>
3028

@@ -60,9 +58,9 @@ getTime()
6058
#endif
6159

6260
double
63-
timeFromISO(std::string_view iso)
61+
timeFromISO(const std::string& iso)
6462
{
65-
std::istringstream in{std::string(iso.data(), iso.size())};
63+
std::istringstream in{iso};
6664
std::tm t = {};
6765
in >> std::get_time(&t, "%Y-%m-%dT%TZ");
6866
return timegm(&t);

cdoc/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ std::vector<std::string> JsonToStringArray(std::string_view json);
8383
// Get time in seconds since the Epoch
8484

8585
double getTime();
86-
double timeFromISO(std::string_view iso);
86+
double timeFromISO(const std::string& iso);
8787
std::string timeToISO(double time);
8888

8989
bool isValidUtf8 (std::string str);

0 commit comments

Comments
 (0)