cool#9992 doc electronic sign: make return type for .uno:Signature consistent

It turns out the majority of getCommandValues() return values specify a
commandName and a commandValues key, which is helpful when we don't
track the request for this reply.

Fix .uno:Signature to do the same for consistency.

Change-Id: I46ffe5c36047ef2b59113d0221a1874ba28d335b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177857
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Miklos Vajna 2024-11-21 08:58:06 +01:00
parent acd9e2165c
commit 0a535147f9
2 changed files with 15 additions and 3 deletions

View file

@ -132,8 +132,14 @@ CPPUNIT_TEST_FIXTURE(Sfx2ViewTest, testLokHelperCommandValuesSignature)
std::stringstream aStream{ std::string(aJson) };
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
auto it = aTree.find("commandName");
CPPUNIT_ASSERT(it != aTree.not_found());
CPPUNIT_ASSERT_EQUAL(std::string(".uno:Signature"), it->second.get_value<std::string>());
it = aTree.find("commandValues");
CPPUNIT_ASSERT(it != aTree.not_found());
aTree = it->second;
// Non-zero timestamp:
auto it = aTree.find("signatureTime");
it = aTree.find("signatureTime");
CPPUNIT_ASSERT(it != aTree.not_found());
auto nSignatureTime = it->second.get_value<sal_Int64>();
CPPUNIT_ASSERT(nSignatureTime != 0);
@ -157,7 +163,10 @@ OUString GetSignatureHash()
std::stringstream aStream{ std::string(aJson) };
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
auto it = aTree.find("digest");
auto it = aTree.find("commandValues");
CPPUNIT_ASSERT(it != aTree.not_found());
aTree = it->second;
it = aTree.find("digest");
CPPUNIT_ASSERT(it != aTree.not_found());
return OUString::fromUtf8(it->second.get_value<std::string>());
}

View file

@ -1030,7 +1030,7 @@ std::map<OUString, OUString> SfxLokHelper::parseCommandParameters(std::u16string
void SfxLokHelper::getCommandValues(tools::JsonWriter& rJsonWriter, std::string_view rCommand)
{
static constexpr OStringLiteral aSignature(".uno:Signature");
static constexpr OString aSignature(".uno:Signature"_ostr);
if (!o3tl::starts_with(rCommand, aSignature))
{
return;
@ -1052,6 +1052,9 @@ void SfxLokHelper::getCommandValues(tools::JsonWriter& rJsonWriter, std::string_
aSigningContext.m_nSignatureTime = it->second.toInt64();
}
pObjectShell->SignDocumentContentUsingCertificate(aSigningContext);
// Set commandName, this is a reply to a request.
rJsonWriter.put("commandName", aSignature);
auto aCommandValues = rJsonWriter.startNode("commandValues");
rJsonWriter.put("signatureTime", aSigningContext.m_nSignatureTime);
uno::Sequence<sal_Int8> aDigest(reinterpret_cast<sal_Int8*>(aSigningContext.m_aDigest.data()),