libdigidocpp
|
#include <BDoc.h>
Public Types | |
enum | Type { BES, TM } |
![]() | |
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 Signature * | getSignature (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) |
![]() | |
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 | |
BDocPrivate * | d |
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).
enum digidoc::BDoc::Type |
digidoc::BDoc::BDoc | ( | const std::string & | path | ) | throw (IOException, BDocException) |
digidoc::BDoc::BDoc | ( | std::auto_ptr< ISerialize > | serializer | ) | throw (IOException, BDocException) |
Opens BDOC container using serializer
implementation.
serializer | implementation of the serializer. |
IOException | exception is thrown if reading data from the container failed. |
BDocException | exception is thrown if the container is not valid. |
|
virtual |
Adds document to the container. Documents can be removed from container only after all signatures are removed.
document | a document, which is added to the container. |
BDocException | exception 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().
|
virtual |
Adds signature to the container. Default profile is TM
signature | signature, which is added to the container. |
BDocException | throws exception if there are no documents in container. |
Implements digidoc::ADoc.
void digidoc::BDoc::addSignature | ( | const std::vector< unsigned char > & | signature, |
Type | profile = TM |
||
) | throw (BDocException) |
Adds signature to the container.
signature | signature, which is added to the container. |
BDocException | throws 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.
|
private |
Adds signature to the container.
signature | signature, which is added to the container. |
BDocException | throws exception if there are no documents in container. |
Definition at line 326 of file BDoc.cpp.
References THROW_BDOCEXCEPTION.
|
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).
IOException | exception 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.
|
private |
Creates mimetype file and returns its path.
IOException | exception 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.
|
virtual |
Implements digidoc::ADoc.
Definition at line 259 of file BDoc.cpp.
Referenced by open().
|
virtual |
Reimplemented from digidoc::ADoc.
|
virtual |
Returns document referenced by document id.
id | document id. |
BDocException | throws exception if the document id is incorrect. |
Implements digidoc::ADoc.
Definition at line 230 of file BDoc.cpp.
References THROW_BDOCEXCEPTION.
Referenced by open().
|
inlinevirtual |
Implements digidoc::ADoc.
|
private |
Definition at line 388 of file BDoc.cpp.
References digidoc::BDocPrivate::MIMETYPE_PREFIX.
|
virtual |
Returns signature referenced by signature id.
id | signature id. |
BDocException | throws 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().
|
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).
path | directory on disk of the BDOC container. |
IOException | exception 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.
|
private |
Initialize BDOC container. Container data is read using serializer
implementation. Container data is validated to correspond to the BDOC specification.
serializer | serializer implementation, used to extract data from BDOC container. |
IOException | is thrown if there was a failure reading BDOC container. For example reading file from disk failed. |
BDocException | is thrown if BDOC container file does not correspond to the specification. |
Definition at line 116 of file BDoc.cpp.
References DEBUG.
|
private |
Reads and parses container mimetype. Checks that the mimetype is supported.
path | path to container directory. |
IOException | exception is thrown if there was error reading mimetype file from disk. |
BDocException | exception 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.
|
virtual |
Removes document from container by document id. Documents can be removed from container only after all signatures are removed.
id | document's id, which will be removed. |
BDocException | throws 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.
|
virtual |
Removes signature from container by signature id.
id | signature's id, which will be removed. |
BDocException | throws exception if the signature id is incorrect. |
Implements digidoc::ADoc.
Definition at line 355 of file BDoc.cpp.
References THROW_BDOCEXCEPTION.
|
virtual |
Saves the container using the serializer
implementation provided in readFrom()
method.
IOException | is thrown if there was a failure saving BDOC container. For example added document does not exist. |
BDocException | is 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.
|
virtual |
Saves the container using the serializer
implementation provided.
path | filepath, used to save data to BDOC container. |
IOException | is thrown if there was a failure saving BDOC container. For example added document does not exist. |
BDocException | is thrown if BDOC class is not correctly initialized. |
Implements digidoc::ADoc.
Definition at line 189 of file BDoc.cpp.
Referenced by create(), and sign().
|
private |
Sets container version.
version | container version. |
Definition at line 380 of file BDoc.cpp.
References digidoc::version().
|
virtual |
Signs all documents in container with default profile TM.
signer | signer implementation. |
BDocException | exception 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().
void digidoc::BDoc::sign | ( | Signer * | signer, |
Type | profile = TM |
||
) | throw (BDocException) |
Signs all documents in container.
signer | signer implementation. |
profile | signature profile (e.g. BES, TM). |
BDocException | exception 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.
|
virtual |
Implements digidoc::ADoc.
Definition at line 370 of file BDoc.cpp.
Referenced by open(), testOpenBDocBES(), testSignBDoc(), and testTMValidate().
|
private |