libcdoc 0.1.8
|
Provides decryption interface. More...
#include <CDocReader.h>
Public Member Functions | |
virtual | ~CDocReader ()=default |
virtual const std::vector< Lock > & | getLocks ()=0 |
Get decryption locks in given document. | |
virtual result_t | getLockForCert (const std::vector< uint8_t > &cert)=0 |
Finds the lock index for given certificate. | |
virtual result_t | getFMK (std::vector< uint8_t > &fmk, unsigned int lock_idx)=0 |
Obtain FMK of given lock. | |
virtual result_t | beginDecryption (const std::vector< uint8_t > &fmk)=0 |
Start decrypting container. | |
virtual result_t | nextFile (std::string &name, int64_t &size)=0 |
Go to the next file in container. | |
virtual result_t | readData (uint8_t *dst, size_t size)=0 |
Read data from the current file. | |
virtual result_t | finishDecryption ()=0 |
Finish decrypting container. | |
result_t | nextFile (FileInfo &info) |
Go to the next file in container. | |
virtual result_t | decrypt (const std::vector< uint8_t > &fmk, MultiDataConsumer *consumer)=0 |
Decrypt document in one step. | |
std::string | getLastErrorStr () const |
Get the error text of the last failed operation. | |
virtual int64_t | testConfig (std::vector< uint8_t > &dst) |
virtual int64_t | testNetwork (std::vector< std::vector< uint8_t > > &dst) |
Static Public Member Functions | |
static int | getCDocFileVersion (const std::string &path) |
Try to determine the cdoc file version. | |
static int | getCDocFileVersion (DataSource *src) |
Try to determine the cdoc file version. | |
static CDocReader * | createReader (DataSource *src, bool take_ownership, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network) |
Create CDoc document reader. | |
static CDocReader * | createReader (const std::string &path, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network) |
Create CDoc document reader. | |
static CDocReader * | createReader (std::istream &ifs, Configuration *conf, CryptoBackend *crypto, NetworkBackend *network) |
Create CDoc document reader. | |
Public Attributes | |
const int | version |
The container version (1 or 2) | |
Protected Member Functions | |
CDocReader (int _version) | |
void | setLastError (const std::string &message) |
Protected Attributes | |
std::string | last_error |
Configuration * | conf = nullptr |
CryptoBackend * | crypto = nullptr |
NetworkBackend * | network = nullptr |
Provides decryption interface.
An abstract base class of CDoc1 and CDoc2 readers. Provides unified interface for loading and decryption of containers.
|
virtualdefault |
|
inlineexplicitprotected |
|
pure virtual |
Start decrypting container.
Starts decryption of the container. This may involve parsing and decrypting headers, checking file and key integrity etc.
fmk | File Master Key of the document |
|
static |
Create CDoc document reader.
Creates a new document reader if file is a valid CDoc container (either version 1 or 2) Configuration and NetworkBackend may be null if keyservers are not used.
path | the path to file |
conf | a configuration object |
crypto | a cryptographic backend implementation |
network | a network backend implementation |
|
static |
Create CDoc document reader.
Creates a new document reader if source is a valid CDoc container (either version 1 or 2). Configuration and NetworkBackend may be null if keyservers are not used.
src | the container source |
take_ownership | if true the source is deleted in reader destructor |
conf | a configuration object |
crypto | a cryptographic backend implementation |
network | a network backend implementation |
|
static |
Create CDoc document reader.
Creates a new document reader if inputstream is a valid CDoc container (either version 1 or 2) Configuration and NetworkBackend may be null if keyservers are not used.
ifs | the input stream |
conf | a configuration object |
crypto | a cryptographic backend implementation |
network | a network backend implementation |
|
pure virtual |
Decrypt document in one step.
Decrypts the encrypted content and writes files to provided output object.
fmk | The FMK of the document |
consumer | a consumer of decrypted files |
|
pure virtual |
Finish decrypting container.
Finishes the decryption of the container. This may onvolve releasing buffers, closing hardware keys etc.
|
static |
Try to determine the cdoc file version.
Tries to open the file and find CDoc format descriptors inside it.
path | a path to file |
|
static |
Try to determine the cdoc file version.
Tries to read the source and find CDoc format descriptors inside it.
src | the container source |
|
pure virtual |
Obtain FMK of given lock.
Obtains FMK (File Master Key) of the lock with given index. Depending on the lock type it uses a relevant CryptoBackend and/or NetworkBackend methods to either fetch secret and derive key or perform external decryption of encrypted KEK.
fmk | The FMK of the document |
lock_idx | the index of a lock (in the document lock list) |
|
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.
|
pure virtual |
Finds the lock index for given certificate.
Returns the first lock that can be opened by the private key of the certificate holder.
cert | a x509 certificate (der) |
|
pure virtual |
Get decryption locks in given document.
Go to the next file in container.
Begins decrypting the next file in container. On success the FileInfo struct is filled and the method returns OK. If there are no more file in the document, END_OF_STREAM is returned. It is OK to call nextFile before reading the whole data from the previous one.
info | a FileInfo structure |
References libcdoc::FileInfo::name, nextFile(), and libcdoc::FileInfo::size.
Referenced by nextFile().
|
pure virtual |
Go to the next file in container.
Begins decrypting the next file in container. On success the file name and size are filled and the method returns OK. If there are no more file in the document, END_OF_STREAM is returned. It is OK to call nextFile before reading the whole data from the previous one. It has to be called always (even for single-file container) immediately after beginDecryption to get access to the first file.
name | the name of the next file |
size | the size of the next file |
|
pure virtual |
Read data from the current file.
Read bytes from the current file (opened with nextFile) inside of the container into the buffer. The number of bytes read is always the requested number, unless end of file is reached or error occurs. Thus the end of file is marked by returning 0.
dst | destination byte buffer |
size | the number of bytes to read |
|
inlineprotected |
|
virtual |
|
virtual |
|
protected |
|
protected |
|
protected |
|
protected |
const int libcdoc::CDocReader::version |
The container version (1 or 2)