libcdoc 0.1.8
libcdoc::CDocWriter Class Referenceabstract

Provides encryption interface. More...

#include <CDocWriter.h>

Public Member Functions

virtual ~CDocWriter ()
 
virtual result_t addRecipient (const Recipient &rcpt)=0
 Add recipient to container.
 
virtual result_t beginEncryption ()=0
 Prepares the stream for encryption.
 
virtual result_t addFile (const std::string &name, size_t size)=0
 Add a new file to the container.
 
virtual result_t writeData (const uint8_t *src, size_t size)=0
 Write data to the encrypted stream.
 
virtual result_t finishEncryption ()=0
 Finalizes the encryption stream.
 
virtual result_t encrypt (MultiDataSource &src, const std::vector< libcdoc::Recipient > &recipients)
 Encrypt data and send to the output stream.
 
std::string getLastErrorStr ()
 Get the error text of the last failed operation.
 

Static Public Member Functions

static CDocWritercreateWriter (int version, DataConsumer *dst, bool take_ownership, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network)
 Create CDoc document writer.
 
static CDocWritercreateWriter (int version, std::ostream &ofs, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network)
 Create CDoc document writer.
 
static CDocWritercreateWriter (int version, const std::string &path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network)
 Create CDoc document writer.
 

Public Attributes

const int version
 The container version (1 or 2)
 

Protected Member Functions

 CDocWriter (int _version, DataConsumer *dst, bool take_ownership)
 
void setLastError (const std::string &message)
 

Protected Attributes

std::string last_error
 
DataConsumerdst
 
bool owned
 
Configurationconf = nullptr
 
CryptoBackendcrypto = nullptr
 
NetworkBackendnetwork = nullptr
 

Detailed Description

Provides encryption interface.

An abstract base class of CDoc1 and CDoc2 writers. Provides an unified interface for file creation and encryption.

Constructor & Destructor Documentation

◆ ~CDocWriter()

virtual libcdoc::CDocWriter::~CDocWriter ( )
virtual

◆ CDocWriter()

libcdoc::CDocWriter::CDocWriter ( int  _version,
DataConsumer dst,
bool  take_ownership 
)
explicitprotected

Member Function Documentation

◆ addFile()

virtual result_t libcdoc::CDocWriter::addFile ( const std::string &  name,
size_t  size 
)
pure virtual

Add a new file to the container.

Start streaming a new file into the container output stream. The name will be written to stream exactly as is. If size is >= 0 the number of bytes subsequently written has to match exactly. Otherwise the final size is determined by the actual number of bytes written.

Parameters
namethe name to be used in container
sizethe size of the file
Returns
error code or OK

◆ addRecipient()

virtual result_t libcdoc::CDocWriter::addRecipient ( const Recipient rcpt)
pure virtual

Add recipient to container.

This adds new recipient to the list of container recipients. FMK (File Master Key) is encrypted separately for each recipient, using corresponding methods. All recipients should be added before the encryption starts.

Parameters
rcpta Recipient object
Returns
error code or OK

◆ beginEncryption()

virtual result_t libcdoc::CDocWriter::beginEncryption ( )
pure virtual

Prepares the stream for encryption.

This may involve creating cryptographic ciphers, building headers and writing the initial part of the stream. All recipients should be added before a call to beginEncryption.

Returns
error code or OK

◆ createWriter() [1/3]

static CDocWriter * libcdoc::CDocWriter::createWriter ( int  version,
const std::string &  path,
Configuration conf,
CryptoBackend crypto,
NetworkBackend network 
)
static

Create CDoc document writer.

Creates a new CDoc document writer for file. Configuration and NetworkBackend may be null if keyservers are not used.

Parameters
version(1 or 2)
pathoutput file path
confa configuration object
cryptoa cryptographic backend implementation
networka network backend implementation
Returns
a new CDocWriter or null

◆ createWriter() [2/3]

static CDocWriter * libcdoc::CDocWriter::createWriter ( int  version,
DataConsumer dst,
bool  take_ownership,
Configuration conf,
CryptoBackend crypto,
NetworkBackend network 
)
static

Create CDoc document writer.

Creates a new CDoc document writer for DataConsumer. Configuration and NetworkBackend may be null if keyservers are not used.

Parameters
version(1 or 2)
dstoutput DataConsumer
take_ownershipwhether to close dst at the end of encryption and delete with CDocWiter
confa configuration object
cryptoa cryptographic backend implementation
networka network backend implementation
Returns
a new CDocWriter or null

◆ createWriter() [3/3]

static CDocWriter * libcdoc::CDocWriter::createWriter ( int  version,
std::ostream &  ofs,
Configuration conf,
CryptoBackend crypto,
NetworkBackend network 
)
static

Create CDoc document writer.

Creates a new CDoc document writer for outputstream. Configuration and NetworkBackend may be null if keyservers are not used.

Parameters
version(1 or 2)
ofsoutput stream
confa configuration object
cryptoa cryptographic backend implementation
networka network backend implementation
Returns
a new CDocWriter or null

◆ encrypt()

virtual result_t libcdoc::CDocWriter::encrypt ( MultiDataSource src,
const std::vector< libcdoc::Recipient > &  recipients 
)
inlinevirtual

Encrypt data and send to the output stream.

Encrypts the data, provided by MultiDataSource, in one go.

Parameters
srcMultiDataSource providing input files (named chunks)
recipientsa list of recipients for whom locks will be encoded into file
Returns
error code or OK

References libcdoc::NOT_IMPLEMENTED.

◆ finishEncryption()

virtual result_t libcdoc::CDocWriter::finishEncryption ( )
pure virtual

Finalizes the encryption stream.

This may involve flushing file, calculating checksum and closing the stream (if owned by CDocWriter)

Returns
error code or OK

◆ getLastErrorStr()

std::string libcdoc::CDocWriter::getLastErrorStr ( )
inline

Get the error text of the last failed operation.

Get the error message of the last failed operation. It should be called immediately after getting error code as certain methods may reset the error.

Returns
error description, empty string if no errors

◆ setLastError()

void libcdoc::CDocWriter::setLastError ( const std::string &  message)
inlineprotected

◆ writeData()

virtual result_t libcdoc::CDocWriter::writeData ( const uint8_t *  src,
size_t  size 
)
pure virtual

Write data to the encrypted stream.

Writes data to the current file (created with addFile) in container. A single file may safely be written in multiple parts as long as the total size matches the one provided in addFile (or the total size was left indeterminate).

Parameters
srcthe source buffer
sizethe size of data in buffer
Returns
size or error code

Member Data Documentation

◆ conf

Configuration* libcdoc::CDocWriter::conf = nullptr
protected

◆ crypto

CryptoBackend* libcdoc::CDocWriter::crypto = nullptr
protected

◆ dst

DataConsumer* libcdoc::CDocWriter::dst
protected

◆ last_error

std::string libcdoc::CDocWriter::last_error
protected

◆ network

NetworkBackend* libcdoc::CDocWriter::network = nullptr
protected

◆ owned

bool libcdoc::CDocWriter::owned
protected

◆ version

const int libcdoc::CDocWriter::version

The container version (1 or 2)


The documentation for this class was generated from the following file: