libdigidocpp
digidoc::BDoc Class Reference

#include <BDoc.h>

Inheritance diagram for digidoc::BDoc:
Inheritance graph
Collaboration diagram for digidoc::BDoc:
Collaboration graph

Public Types

enum  Type { BES, TM }
- Public Types inherited from digidoc::ADoc
enum  DocumentType { UnknownType = 0, BDocType = 1, DDocType = 2 }

Public Member Functions

 BDoc ()
 BDoc (const std::string &path) throw (IOException, BDocException)
 BDoc (std::auto_ptr< ISerialize > serializer) throw (IOException, BDocException)
virtual ~BDoc ()
void save () throw (IOException, BDocException)
void saveTo (const std::string &path) throw (IOException, BDocException)
void addDocument (const Document &document) throw (BDocException)
Document getDocument (unsigned int id) const throw (BDocException)
void removeDocument (unsigned int id) throw (BDocException)
unsigned int documentCount () const
DocumentType documentType () const
void addSignature (const std::vector< unsigned char > &signature) throw (BDocException)
void addSignature (const std::vector< unsigned char > &signature, Type profile=TM) throw (BDocException)
const SignaturegetSignature (unsigned int id) const throw (BDocException)
void removeSignature (unsigned int id) throw (BDocException)
unsigned int signatureCount () const
void sign (Signer *signer) throw (BDocException)
void sign (Signer *signer, Type profile=TM) throw (BDocException)
std::vector< unsigned char > getFileDigest (unsigned int) throw (BDocException)
- Public Member Functions inherited from digidoc::ADoc
virtual ~ADoc ()
unsigned int newSignatureId () const

Private Member Functions

void readFrom (std::auto_ptr< ISerialize > serializer) throw (IOException, BDocException)
void addSignature (Signature *signature) throw (BDocException)
void setVersion (const std::string &version)
std::string getMimeType () const
std::string createMimetype () throw (IOException)
std::string createManifest () throw (IOException)
void readMimetype (const std::string &path) throw (IOException, BDocException)
void parseManifestAndLoadFiles (const std::string &path) throw (IOException, BDocException)

Private Attributes

BDocPrivated

Detailed Description

Implements the BDOC specification of the signed digital document container. Container can contain several files and all these files can be signed using signing certificates. Container can only be signed if it contains documents. Documents can be added and removed from container only if the container is not signed. To add or remove documents from signed container remove all the signatures before modifying documents list in container.

Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly (see iconv –list for the list of supported encoding values for libiconv).

Author
Janari Põld

Definition at line 43 of file BDoc.h.

Member Enumeration Documentation

Enumerator:
BES 
TM 

Definition at line 47 of file BDoc.h.

Constructor & Destructor Documentation

digidoc::BDoc::BDoc ( )

Initialize BDOC container.

Definition at line 64 of file BDoc.cpp.

digidoc::BDoc::BDoc ( const std::string &  path) throw (IOException, BDocException)

Opens BDOC container from a file

Definition at line 73 of file BDoc.cpp.

digidoc::BDoc::BDoc ( std::auto_ptr< ISerialize serializer) throw (IOException, BDocException)

Opens BDOC container using serializer implementation.

Parameters
serializerimplementation of the serializer.
Exceptions
IOExceptionexception is thrown if reading data from the container failed.
BDocExceptionexception is thrown if the container is not valid.

Definition at line 87 of file BDoc.cpp.

digidoc::BDoc::~BDoc ( )
virtual

Releases resources.

Definition at line 96 of file BDoc.cpp.

Member Function Documentation

void digidoc::BDoc::addDocument ( const Document document) throw (BDocException)
virtual

Adds document to the container. Documents can be removed from container only after all signatures are removed.

Parameters
documenta document, which is added to the container.
Exceptions
BDocExceptionexception is thrown if the document path is incorrect or document with same file name already exists. Also no document can be added if the container already has one or more signatures.

Implements digidoc::ADoc.

Definition at line 204 of file BDoc.cpp.

References digidoc::util::File::fileExists(), and THROW_BDOCEXCEPTION.

Referenced by create(), testSignBDoc(), and testTMValidate().

Here is the call graph for this function:

Here is the caller graph for this function:

void digidoc::BDoc::addSignature ( const std::vector< unsigned char > &  signature) throw (BDocException)
virtual

Adds signature to the container. Default profile is TM

Parameters
signaturesignature, which is added to the container.
Exceptions
BDocExceptionthrows exception if there are no documents in container.

Implements digidoc::ADoc.

Definition at line 278 of file BDoc.cpp.

void digidoc::BDoc::addSignature ( const std::vector< unsigned char > &  signature,
Type  profile = TM 
) throw (BDocException)

Adds signature to the container.

Parameters
signaturesignature, which is added to the container.
Exceptions
BDocExceptionthrows exception if there are no documents in container.

Definition at line 289 of file BDoc.cpp.

References digidoc::util::File::encodeName(), i, digidoc::util::File::tempFileName(), and THROW_BDOCEXCEPTION.

Here is the call graph for this function:

void digidoc::BDoc::addSignature ( Signature signature) throw (BDocException)
private

Adds signature to the container.

Parameters
signaturesignature, which is added to the container.
Exceptions
BDocExceptionthrows exception if there are no documents in container.

Definition at line 326 of file BDoc.cpp.

References THROW_BDOCEXCEPTION.

std::string digidoc::BDoc::createManifest ( ) throw (IOException)
private

Creates BDoc container manifest file and returns its path.

Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly (see iconv –list for the list of supported encoding values for libiconv).

Returns
returns created manifest file path.
Exceptions
IOExceptionexception is thrown if manifest file creation failed.

Definition at line 425 of file BDoc.cpp.

References DEBUG, e, digidoc::util::File::encodeName(), digidoc::Log::format(), i, digidoc::BDocPrivate::MANIFEST_NAMESPACE, digidoc::util::File::tempFileName(), and THROW_IOEXCEPTION.

Here is the call graph for this function:

std::string digidoc::BDoc::createMimetype ( ) throw (IOException)
private

Creates mimetype file and returns its path.

Returns
returns path to created mimetype file.
Exceptions
IOExceptionexception is thrown if file creation failed.

Definition at line 399 of file BDoc.cpp.

References DEBUG, digidoc::util::File::encodeName(), digidoc::util::File::tempFileName(), and THROW_IOEXCEPTION.

Here is the call graph for this function:

unsigned int digidoc::BDoc::documentCount ( ) const
virtual
Returns
returns number of documents in container.

Implements digidoc::ADoc.

Definition at line 259 of file BDoc.cpp.

Referenced by open().

Here is the caller graph for this function:

digidoc::ADoc::DocumentType digidoc::BDoc::documentType ( ) const
virtual
Returns
returns container type.

Reimplemented from digidoc::ADoc.

Definition at line 267 of file BDoc.cpp.

digidoc::Document digidoc::BDoc::getDocument ( unsigned int  id) const throw (BDocException)
virtual

Returns document referenced by document id.

Parameters
iddocument id.
Returns
returns document referenced by document id.
Exceptions
BDocExceptionthrows exception if the document id is incorrect.

Implements digidoc::ADoc.

Definition at line 230 of file BDoc.cpp.

References THROW_BDOCEXCEPTION.

Referenced by open().

Here is the caller graph for this function:

std::vector<unsigned char> digidoc::BDoc::getFileDigest ( unsigned int  ) throw (BDocException)
inlinevirtual

Implements digidoc::ADoc.

Definition at line 67 of file BDoc.h.

std::string digidoc::BDoc::getMimeType ( ) const
private
Returns
returns BDoc container mimetype.

Definition at line 388 of file BDoc.cpp.

References digidoc::BDocPrivate::MIMETYPE_PREFIX.

const digidoc::Signature * digidoc::BDoc::getSignature ( unsigned int  id) const throw (BDocException)
virtual

Returns signature referenced by signature id.

Parameters
idsignature id.
Returns
returns signature referenced by signature id.
Exceptions
BDocExceptionthrows exception if the signature id is incorrect.

Implements digidoc::ADoc.

Definition at line 342 of file BDoc.cpp.

References THROW_BDOCEXCEPTION.

Referenced by open(), testOpenBDocBES(), testSignBDoc(), and testTMValidate().

Here is the caller graph for this function:

void digidoc::BDoc::parseManifestAndLoadFiles ( const std::string &  path) throw (IOException, BDocException)
private

Parses manifest file and checks that files described in manifest exist, also checks that no extra file do exist that are not described in manifest.xml.

Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly (see iconv –list for the list of supported encoding values for libiconv).

Parameters
pathdirectory on disk of the BDOC container.
Exceptions
IOExceptionexception is thrown if the manifest.xml file parsing failed.
BDocException

Definition at line 523 of file BDoc.cpp.

References DEBUG, digidoc::util::File::decodeName(), e, digidoc::util::File::fileExists(), digidoc::util::File::fileName(), digidoc::Conf::getInstance(), digidoc::util::File::listFiles(), digidoc::BDocPrivate::MANIFEST_NAMESPACE, digidoc::SignatureBES::MEDIA_TYPE, digidoc::SignatureTM::MEDIA_TYPE, digidoc::util::File::path(), THROW_BDOCEXCEPTION, THROW_BDOCEXCEPTION_CAUSE, and THROW_IOEXCEPTION.

Here is the call graph for this function:

void digidoc::BDoc::readFrom ( std::auto_ptr< ISerialize serializer) throw (IOException, BDocException)
private

Initialize BDOC container. Container data is read using serializer implementation. Container data is validated to correspond to the BDOC specification.

Parameters
serializerserializer implementation, used to extract data from BDOC container.
Exceptions
IOExceptionis thrown if there was a failure reading BDOC container. For example reading file from disk failed.
BDocExceptionis thrown if BDOC container file does not correspond to the specification.

Definition at line 116 of file BDoc.cpp.

References DEBUG.

void digidoc::BDoc::readMimetype ( const std::string &  path) throw (IOException, BDocException)
private

Reads and parses container mimetype. Checks that the mimetype is supported.

Parameters
pathpath to container directory.
Exceptions
IOExceptionexception is thrown if there was error reading mimetype file from disk.
BDocExceptionexception is thrown if the parsed mimetype is incorrect.

Definition at line 482 of file BDoc.cpp.

References DEBUG, digidoc::util::File::encodeName(), digidoc::util::File::path(), THROW_BDOCEXCEPTION, and THROW_IOEXCEPTION.

Here is the call graph for this function:

void digidoc::BDoc::removeDocument ( unsigned int  id) throw (BDocException)
virtual

Removes document from container by document id. Documents can be removed from container only after all signatures are removed.

Parameters
iddocument's id, which will be removed.
Exceptions
BDocExceptionthrows exception if the document id is incorrect or there are one or more signatures.

Implements digidoc::ADoc.

Definition at line 245 of file BDoc.cpp.

References THROW_BDOCEXCEPTION.

void digidoc::BDoc::removeSignature ( unsigned int  id) throw (BDocException)
virtual

Removes signature from container by signature id.

Parameters
idsignature's id, which will be removed.
Exceptions
BDocExceptionthrows exception if the signature id is incorrect.

Implements digidoc::ADoc.

Definition at line 355 of file BDoc.cpp.

References THROW_BDOCEXCEPTION.

void digidoc::BDoc::save ( ) throw (IOException, BDocException)
virtual

Saves the container using the serializer implementation provided in readFrom() method.

Exceptions
IOExceptionis thrown if there was a failure saving BDOC container. For example added document does not exist.
BDocExceptionis thrown if BDoc class is not correctly initialized.

Implements digidoc::ADoc.

Definition at line 141 of file BDoc.cpp.

References digidoc::Log::format(), i, and THROW_BDOCEXCEPTION.

Here is the call graph for this function:

void digidoc::BDoc::saveTo ( const std::string &  path) throw (IOException, BDocException)
virtual

Saves the container using the serializer implementation provided.

Parameters
pathfilepath, used to save data to BDOC container.
Exceptions
IOExceptionis thrown if there was a failure saving BDOC container. For example added document does not exist.
BDocExceptionis thrown if BDOC class is not correctly initialized.
See Also
save()

Implements digidoc::ADoc.

Definition at line 189 of file BDoc.cpp.

Referenced by create(), and sign().

Here is the caller graph for this function:

void digidoc::BDoc::setVersion ( const std::string &  version)
private

Sets container version.

Parameters
versioncontainer version.

Definition at line 380 of file BDoc.cpp.

References digidoc::version().

Here is the call graph for this function:

void digidoc::BDoc::sign ( Signer signer) throw (BDocException)
virtual

Signs all documents in container with default profile TM.

Parameters
signersigner implementation.
Exceptions
BDocExceptionexception is throws if signing the BDCO container failed.

Implements digidoc::ADoc.

Definition at line 649 of file BDoc.cpp.

References sign().

Referenced by create(), sign(), testSignBDoc(), and testTMValidate().

Here is the call graph for this function:

Here is the caller graph for this function:

void digidoc::BDoc::sign ( Signer signer,
Type  profile = TM 
) throw (BDocException)

Signs all documents in container.

Parameters
signersigner implementation.
profilesignature profile (e.g. BES, TM).
Exceptions
BDocExceptionexception is throws if signing the BDCO container failed.

Definition at line 661 of file BDoc.cpp.

References DEBUG, e, digidoc::Signature::sign(), THROW_BDOCEXCEPTION, and THROW_BDOCEXCEPTION_CAUSE.

Here is the call graph for this function:

unsigned int digidoc::BDoc::signatureCount ( ) const
virtual
Returns
returns number of signatures in container.

Implements digidoc::ADoc.

Definition at line 370 of file BDoc.cpp.

Referenced by open(), testOpenBDocBES(), testSignBDoc(), and testTMValidate().

Here is the caller graph for this function:

Member Data Documentation

BDocPrivate* digidoc::BDoc::d
private

Definition at line 79 of file BDoc.h.


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