libdigidocpp  4.0.0
digidoc::Container Class Referenceabstract

Offers functionality for handling data files and signatures in a container. More...

#include <Container.h>

Public Member Functions

virtual ~Container ()
 
virtual void save (const std::string &path="")=0
 
virtual std::string mediaType () const =0
 
virtual void addDataFile (const std::string &path, const std::string &mediaType)=0
 
virtual DIGIDOCPP_DEPRECATED void addDataFile (std::istream *is, const std::string &fileName, const std::string &mediaType)
 
virtual std::vector< DataFile * > dataFiles () const =0
 
virtual void removeDataFile (unsigned int index)=0
 
void addAdESSignature (const std::vector< unsigned char > &signature)
 
virtual void addAdESSignature (std::istream &signature)=0
 
virtual SignatureprepareSignature (Signer *signer)=0
 
virtual std::vector< Signature * > signatures () const =0
 
virtual void removeSignature (unsigned int index)=0
 
virtual Signaturesign (Signer *signer)=0
 
virtual void addDataFile (std::unique_ptr< std::istream > is, const std::string &fileName, const std::string &mediaType)
 

Static Public Member Functions

static DIGIDOCPP_DEPRECATED Containercreate (const std::string &path)
 
static std::unique_ptr< ContainercreatePtr (const std::string &path)
 
static DIGIDOCPP_DEPRECATED Containeropen (const std::string &path)
 
static std::unique_ptr< ContaineropenPtr (const std::string &path)
 
static std::unique_ptr< ContaineropenPtr (const std::string &path, digidoc::ContainerOpenCB *cb)
 
template<class T >
static void addContainerImplementation ()
 

Protected Member Functions

 Container ()
 
unsigned int newSignatureId () const
 

Detailed Description

Offers functionality for handling data files and signatures in a container.

Container can contain several files and all these files can be signed using signing certificates. Container can only be signed if it contains data files. data files can be added and removed from container only if the container is not signed. To add or remove data files from signed container remove all the signatures before modifying data files list in container.

Constructor & Destructor Documentation

◆ ~Container()

Container::~Container ( )
virtualdefault

Releases resources.

◆ Container()

Container::Container ( )
protecteddefault

Create a new container object and specify the DigiDoc container type

Member Function Documentation

◆ addAdESSignature() [1/2]

void Container::addAdESSignature ( const std::vector< unsigned char > &  signature)

Adds signature to the container.

Parameters
signaturesignature, which is added to the container.
Exceptions
Exceptionthrows exception if there are no data files in container.

◆ addAdESSignature() [2/2]

digidoc::Container::addAdESSignature ( std::istream &  signature)
pure virtual

Adds signature to the container.

Parameters
signaturesignature, which is added to the container.
Exceptions
Exceptionthrows exception if there are no data files in container.

◆ addContainerImplementation()

template<class T >
void Container::addContainerImplementation
static

Adds container implementation

It must contain static members:

  • static Container* createInternal(const std::string &path);
  • static Container* openInternal(const std::string &path, digidoc::ContainerOpenCB *cb);
See also
Container::create, Container::open

◆ addDataFile() [1/3]

digidoc::Container::addDataFile ( const std::string &  path,
const std::string &  mediaType 
)
pure virtual

Adds data file from file system to the container.

Parameters
patha data file, which is added to the container.
mediaTypeMIME type of the data file, for example “text/plain” or “application/msword”
Exceptions
Exceptionexception is thrown if the data file path is incorrect or a data file with same file name already exists. Also, no data file can be added if the container already has one or more signatures.
Note
Data files can be removed from container only after all signatures are removed.

◆ addDataFile() [2/3]

void Container::addDataFile ( std::istream *  is,
const std::string &  fileName,
const std::string &  mediaType 
)
virtual

Adds the data from an input stream (i.e. the data file contents can be read from internal memory buffer).

Takes ownership std::istream *is object.

Deprecated:
Use digidoc::Container::addDataFile(std::unique_ptr<std::istream> is, const std::string &fileName, const std::string &mediaType)
Parameters
isinput stream from where data is read
fileNamedata file name in the container
mediaTypeMIME type of the data file, for example “text/plain” or “application/msword”
Exceptions
Exceptionexception is thrown if the data file path is incorrect or a data file with same file name already exists. Also, no data file can be added if the container already has one or more signatures.
Note
Data files can be removed from container only after all signatures are removed.

◆ addDataFile() [3/3]

void Container::addDataFile ( std::unique_ptr< std::istream >  is,
const std::string &  fileName,
const std::string &  mediaType 
)
virtual

Adds the data from an input stream (i.e. the data file contents can be read from internal memory buffer).

Parameters
isinput stream from where data is read
fileNamedata file name in the container
mediaTypeMIME type of the data file, for example “text/plain” or “application/msword”
Exceptions
Exceptionexception is thrown if the data file path is incorrect or a data file with same file name already exists. Also, no data file can be added if the container already has one or more signatures.
Note
Data files can be removed from container only after all signatures are removed.

◆ create()

Container * Container::create ( const std::string &  path)
static

Create a new container object and specify the DigiDoc container type

Deprecated:
Use Container::createPtr This method gives ownership of object to caller

◆ createPtr()

unique_ptr< Container > Container::createPtr ( const std::string &  path)
static

Create a new container object and specify the DigiDoc container type

◆ dataFiles()

digidoc::Container::dataFiles ( ) const
pure virtual

List of all the data files in the container

Container holds ownership of data files objects

◆ mediaType()

digidoc::Container::mediaType ( ) const
pure virtual

Returns current data file format

◆ newSignatureId()

unsigned int Container::newSignatureId ( ) const
protected

Returns unique signature id

◆ open()

Container * Container::open ( const std::string &  path)
static

Opens container from a file

This method gives ownership of object to caller

Deprecated:
Use Container::openPtr
Parameters
path
Exceptions
Exception

◆ openPtr() [1/2]

unique_ptr< Container > Container::openPtr ( const std::string &  path)
static

Opens container from a file

Parameters
path
Exceptions
Exception

◆ openPtr() [2/2]

unique_ptr< Container > Container::openPtr ( const std::string &  path,
digidoc::ContainerOpenCB cb 
)
static

Opens container from a file

Parameters
path
cbCallback called when additional info is requested (digidoc::ContainerOpenCB::validateOnline)
Exceptions
Exception

◆ prepareSignature()

digidoc::Container::prepareSignature ( Signer signer)
pure virtual

Prepares Signature object that can later signed.

Container holds ownership of Signature object

See also
digidoc::Signature::dataToSign
digidoc::Signature::setSignatureValue
digidoc::Signature::extendSignatureProfile
Parameters
signersigner implementation.
Exceptions
Exceptionexception is thrown if signing the container failed.

◆ removeDataFile()

digidoc::Container::removeDataFile ( unsigned int  index)
pure virtual

Removes data file from container by data file index. Data files can be removed from container only after all signatures are removed.

Parameters
indexdata file's index, which will be removed.
Exceptions
Exceptionthrows exception if the data file id is incorrect or there are one or more signatures.
See also
digidoc::Container::dataFiles

◆ removeSignature()

digidoc::Container::removeSignature ( unsigned int  index)
pure virtual

Removes signature from container by signature index.

Parameters
indexsignature's index, which will be removed.
Exceptions
Exceptionthrows exception if the signature id is incorrect.
See also
digidoc::Container::signatures

◆ save()

digidoc::Container::save ( const std::string &  path = "")
pure virtual

Saves the container.

Exceptions
Exceptionis thrown if there was a failure saving container. For example added data file does not exist.

◆ sign()

digidoc::Container::sign ( Signer signer)
pure virtual

Signs all data files in container.

This method does not take ownership of signer object. Container holds ownership of Signature object.

Parameters
signersigner implementation.
Exceptions
Exceptionexception is thrown if signing the container failed.

◆ signatures()

digidoc::Container::signatures ( ) const
pure virtual

Returns list of all container's signatures.

Container holds ownership of signature objects


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