libdigidocpp 4.5.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 ()
 
static std::unique_ptr< ContainerextendContainerValidity (Container &doc, Signer *signer, size_t &extendedCount)
 

Protected Member Functions

virtual std::string path () const
 
 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.

References addAdESSignature().

Referenced by addAdESSignature().

◆ 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.

Referenced by addDataFile().

◆ 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:
Since 3.14.4, 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.

References addDataFile(), and mediaType().

◆ 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).

Since
3.14.4
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:
Since 3.14.4, use Container::createPtr This method gives ownership of object to caller

References createPtr(), and path().

Referenced by createPtr().

◆ createPtr()

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

Create a new container object and specify the DigiDoc container type

Since
3.14.4

References create(), and path().

Referenced by create().

◆ dataFiles()

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

List of all the data files in the container

Container holds ownership of data files objects

◆ extendContainerValidity()

std::unique_ptr< Container > Container::extendContainerValidity ( Container doc,
Signer signer,
size_t &  extendedCount 
)
static

Extends the validity of signatures in the container by adding a new timestamp.

For ASiC-E and ASiC-S containers, considers only signatures whose signing certificate has country=EE; non-Estonian signatures are ignored when deciding whether extension is possible. For ASiC-E containers with valid LT-level EE signatures, extends eligible non-e-seal signatures in place by adding an archive timestamp. For ASiC-S containers, re-timestamps the existing EE timestamp token. If in-place extension is not possible, wraps the original container as a data file in a new ASiC-S container and adds a timestamp.

Containers where all considered EE signatures are T-level (time-stamp profile without OCSP) cannot be extended and will throw. Containers with no Estonian signing certificates will throw.

Parameters
doccontainer whose signatures are to be extended.
signersigner used to create the new timestamp; its profile will be set automatically.
extendedCountset to the number of signatures extended in place; 0 if the container was wrapped.
Returns
new ASiC-S container if wrapping was necessary; empty unique_ptr if extended in place.
Exceptions
Exceptionif the container has no signatures, no EE signatures, all signatures are T-level, or extension fails.
Since
4.5.0

References digidoc::Exception::causes(), digidoc::Exception::CertificateIssuerMissing, digidoc::Exception::CertificateUnknown, mediaType(), digidoc::Exception::MimeTypeWarning, digidoc::Exception::OCSPCertMissing, digidoc::Exception::OCSPResponderMissing, path(), digidoc::X509Cert::QCT_ESEAL, digidoc::Signer::setProfile(), and signatures().

◆ mediaType()

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

Returns current data file format

Referenced by addDataFile(), and extendContainerValidity().

◆ newSignatureId()

unsigned int Container::newSignatureId ( ) const
protected

Returns unique signature id

References digidoc::Signature::id(), and signatures().

◆ open()

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

Opens container from a file

This method gives ownership of object to caller

Deprecated:
Since 3.14.4, use Container::openPtr
Parameters
path
Exceptions
Exception

References openPtr(), and path().

Referenced by openPtr().

◆ openPtr() [1/2]

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

Opens container from a file

Since
3.14.4
Parameters
path
Exceptions
Exception

References openPtr(), and path().

Referenced by open(), and openPtr().

◆ openPtr() [2/2]

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

Opens container from a file

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

References open(), and path().

◆ path()

string Container::path ( ) const
protectedvirtual

Returns the path of the container.

Returns
path of the container.
Since
4.5.0

Referenced by create(), createPtr(), extendContainerValidity(), open(), openPtr(), and openPtr().

◆ 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

Referenced by extendContainerValidity(), and newSignatureId().


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