Skip to content

Commit 8ffec98

Browse files
authored
Don't remove whitespace from xml text element (#647)
IB-8297 Signed-off-by: Raul Metsma <[email protected]>
1 parent d4c5c5d commit 8ffec98

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/SignatureXAdES_B.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "crypto/X509CertStore.h"
2929
#include "crypto/X509Crypto.h"
3030
#include "util/DateTime.h"
31+
#include "util/algorithm.h"
3132
#include "util/log.h"
3233
#include "util/File.h"
3334

@@ -364,7 +365,7 @@ string SignatureXAdES_B::policy() const
364365
{
365366
if(auto id = signedSignatureProperties()/"SignaturePolicyIdentifier"/"SignaturePolicyId"/"SigPolicyId"/"Identifier";
366367
id && id["Qualifier"] == "OIDAsURN")
367-
return string(id);
368+
return string(trim_prefix(id));
368369
return {};
369370
}
370371

@@ -393,8 +394,8 @@ string SignatureXAdES_B::trustedSigningTime() const
393394

394395
string SignatureXAdES_B::SPUri() const
395396
{
396-
return string(signedSignatureProperties()
397-
/"SignaturePolicyIdentifier"/"SignaturePolicyId"/"SigPolicyQualifiers"/"SigPolicyQualifier"/"SPURI");
397+
return string(trim_prefix(signedSignatureProperties()
398+
/"SignaturePolicyIdentifier"/"SignaturePolicyId"/"SigPolicyQualifiers"/"SigPolicyQualifier"/"SPURI"));
398399
}
399400

400401
void SignatureXAdES_B::validate() const
@@ -633,7 +634,7 @@ void SignatureXAdES_B::checkSigningCertificate(bool noqscd) const
633634
{
634635
X509Cert signingCert = signingCertificate();
635636
vector<X509Cert::KeyUsage> usage = signingCert.keyUsage();
636-
if(find(usage.cbegin(), usage.cend(), X509Cert::NonRepudiation) == usage.cend())
637+
if(!contains(usage, X509Cert::NonRepudiation))
637638
THROW("Signing certificate does not contain NonRepudiation key usage flag");
638639
if(!X509CertStore::instance()->verify(signingCert, noqscd))
639640
THROW("Unable to verify signing certificate");

src/XMLDocument.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,8 @@ struct XMLElem
173173

174174
constexpr operator sv() const noexcept
175175
{
176-
constexpr sv whitespace {" \n\r\f\t\v"};
177176
auto *text = children(&value_type::children, XML_TEXT_NODE);
178-
auto result = to_string_view(text, &std::decay_t<decltype(*text)>::content);
179-
result.remove_prefix(std::min<size_t>(result.find_first_not_of(whitespace), result.size()));
180-
return result;
177+
return to_string_view(text, &std::decay_t<decltype(*text)>::content);
181178
}
182179

183180
pointer d{};

src/util/algorithm.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ constexpr bool none_of(const C &list, P pred)
5454

5555
template<typename T>
5656
[[nodiscard]]
57-
constexpr bool starts_with(T str, T needle) {
57+
constexpr bool starts_with(T str, std::string_view needle) {
5858
return str.size() >= needle.size() && str.compare(0, needle.size(), needle) == 0;
5959
}
6060

61+
[[nodiscard]]
62+
constexpr auto trim_prefix(std::string_view src)
63+
{
64+
constexpr std::string_view whitespace {" \n\r\f\t\v"};
65+
return src.substr(std::min<size_t>(src.find_first_not_of(whitespace), src.size()));
66+
}
67+
6168
}

0 commit comments

Comments
 (0)