Skip to content

Commit

Permalink
Store previous signature in memory (#591)
Browse files Browse the repository at this point in the history
* Store previous signature in memory

IB-8030

Signed-off-by: Raul Metsma <[email protected]>

* Update unittest data

IB-8010

Signed-off-by: Raul Metsma <[email protected]>

---------

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored May 6, 2024
1 parent e67faa5 commit d2ce45d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/SignatureXAdES_B.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ Signatures::Signatures(istream &data, ASiContainer *container)
properties.schema_location(URI_ID_DSIG, File::fullPathUrl(xsdPath + "/xmldsig-core-schema.xsd"));
properties.schema_location(ASIC_NAMESPACE, File::fullPathUrl(xsdPath + "/en_31916201v010101.xsd"));
properties.schema_location(OPENDOCUMENT_NAMESPACE, File::fullPathUrl(xsdPath + "/OpenDocument_dsig.xsd"));
parseDOM(data, properties.schema_location());
copy << data.rdbuf();

parseDOM(copy, properties.schema_location());

try
{
Expand Down Expand Up @@ -208,12 +210,20 @@ void Signatures::reloadDOM()
// Save to file an parse it again, to make XML Canonicalization work
// correctly as expected by the Canonical XML 1.0 specification.
// Hope, the next Canonical XMl specification fixes the white spaces preserving "bug".
stringstream ofs;
save(ofs);
parseDOM(ofs);
copy.str({});
copy.clear();
saveXML(copy);
parseDOM(copy);
}

void Signatures::save(ostream &os) const
{
if(copy.str().empty())
return saveXML(os);
os << copy.str();
}

void Signatures::saveXML(ostream &os) const
{
try
{
Expand Down
3 changes: 3 additions & 0 deletions src/SignatureXAdES_B.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <map>
#include <memory>
#include <sstream>

namespace digidoc
{
Expand Down Expand Up @@ -57,8 +58,10 @@ namespace digidoc

private:
void parseDOM(std::istream &data, const std::string &schema_location = {});
void saveXML(std::ostream &os) const;

std::unique_ptr<xercesc::DOMDocument> doc;
std::stringstream copy;
};

class SignatureXAdES_B : public Signature
Expand Down

0 comments on commit d2ce45d

Please sign in to comment.