Skip to content

Commit

Permalink
Workaround c++20 has stringstream move override
Browse files Browse the repository at this point in the history
IB-7851

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Oct 27, 2023
1 parent 7dc3ce9 commit 149b204
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/SiVaContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ using namespace std;
using namespace xercesc;
using json = nlohmann::json;

static string base64_decode(const XMLCh *in) {
static auto base64_decode(const XMLCh *in) {
static constexpr array<uint8_t, 128> T{
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
Expand All @@ -65,7 +65,7 @@ static string base64_decode(const XMLCh *in) {
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x64, 0x64, 0x64, 0x64, 0x64
};

string out;
auto out = make_unique<stringstream>();
int value = 0;
int bits = -8;
for(; in; ++in)
Expand All @@ -77,9 +77,9 @@ static string base64_decode(const XMLCh *in) {
if(check == 0x64)
break;
value = (value << 6) + check;
if((bits += 6) < 0)
if(bits += 6; bits < 0)
continue;
out.push_back(char((value >> bits) & 0xFF));
out->put(char((value >> bits) & 0xFF));
bits -= 8;
}
return out;
Expand Down Expand Up @@ -162,7 +162,7 @@ SiVaContainer::SiVaContainer(const string &path, const string &ext, bool useHash
d->dataFiles.push_back(new DataFilePrivate(std::move(ifs), fileName, "application/pdf"));
}

array<XMLByte, 48*100> buf{};
array<XMLByte, 4800> buf{};
string b64;
is->clear();
is->seekg(0);
Expand Down Expand Up @@ -337,7 +337,7 @@ unique_ptr<istream> SiVaContainer::parseDDoc(bool useHashCode)
DOMNodeList *nodeList = dom->getElementsByTagName(cpXMLCh(u"DataFile"));
for(XMLSize_t i = 0; i < nodeList->getLength(); ++i)
{
DOMElement *item = static_cast<DOMElement*>(nodeList->item(i));
auto *item = static_cast<DOMElement*>(nodeList->item(i));
if(!item)
continue;

Expand All @@ -348,7 +348,7 @@ unique_ptr<istream> SiVaContainer::parseDDoc(bool useHashCode)

if(const XMLCh *b64 = item->getTextContent())
{
d->dataFiles.push_back(new DataFilePrivate(make_unique<stringstream>(base64_decode(b64)),
d->dataFiles.push_back(new DataFilePrivate(base64_decode(b64),
xml::transcode<char>(item->getAttribute(cpXMLCh(u"Filename"))),
xml::transcode<char>(item->getAttribute(cpXMLCh(u"MimeType"))),
xml::transcode<char>(item->getAttribute(cpXMLCh(u"Id")))));
Expand All @@ -359,8 +359,7 @@ unique_ptr<istream> SiVaContainer::parseDDoc(bool useHashCode)
Digest calc(URI_SHA1);
SecureDOMParser::calcDigestOnNode(&calc, "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", item);
vector<unsigned char> digest = calc.result();
XMLSize_t size = 0;
if(XMLByte *out = Base64::encode(digest.data(), XMLSize_t(digest.size()), &size))
if(XMLSize_t size = 0; XMLByte *out = Base64::encode(digest.data(), XMLSize_t(digest.size()), &size))
{
item->setAttribute(cpXMLCh(u"ContentType"), cpXMLCh(u"HASHCODE"));
item->setAttribute(cpXMLCh(u"DigestType"), cpXMLCh(u"sha1"));
Expand Down

0 comments on commit 149b204

Please sign in to comment.