Kaydet (Commit) 88cbfe58 authored tarafından Miklos Vajna's avatar Miklos Vajna

xmlsecurity: add XMLSignatureHelper::SetDescription()

First step to be able to add a comment while signing a document.

Change-Id: I8f7ab95de5015b723481e94bd72585caf754288f
üst 679cc560
......@@ -74,6 +74,10 @@ struct SignatureInformation
OUString ouDateTime;
OUString ouSignatureId;
OUString ouPropertyId;
/// Characters of the <dc:description> element inside the signature.
OUString ouDescription;
/// The Id attribute of the <SignatureProperty> element that contains the <dc:description>.
OUString ouDescriptionPropertyId;
SignatureInformation( sal_Int32 nId )
{
......
......@@ -164,6 +164,7 @@ public:
const OUString& ouX509SerialNumber, const OUString& ouX509Cert);
void SetDateTime( sal_Int32 nSecurityId, const Date& rDate, const tools::Time& rTime );
void SetDescription(sal_Int32 nSecurityId, const OUString& rDescription);
void AddForSigning( sal_Int32 securityId, const OUString& uri, const OUString& objectURL, bool bBinary );
bool CreateAndWriteSignature( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler >& xDocumentHandler );
......
......@@ -128,6 +128,11 @@ void XMLSignatureHelper::SetDateTime( sal_Int32 nSecurityId, const ::Date& rDate
mpXSecController->setDate( nSecurityId, stDateTime );
}
void XMLSignatureHelper::SetDescription(sal_Int32 nSecurityId, const OUString& rDescription)
{
mpXSecController->setDescription(nSecurityId, rDescription);
}
void XMLSignatureHelper::AddForSigning( sal_Int32 nSecurityId, const OUString& uri, const OUString& objectURL, bool bBinary )
{
mpXSecController->signAStream( nSecurityId, uri, objectURL, bBinary );
......
......@@ -37,6 +37,7 @@ namespace cssl = com::sun::star::lang;
namespace cssxc = com::sun::star::xml::crypto;
namespace cssxs = com::sun::star::xml::sax;
namespace cssxw = com::sun::star::xml::wrapper;
using namespace com::sun::star;
/* bridge component names */
#define XMLSIGNATURE_COMPONENT "com.sun.star.xml.crypto.XMLSignature"
......@@ -725,6 +726,7 @@ void XSecController::exportSignature(
OUString tag_SignatureProperties(TAG_SIGNATUREPROPERTIES);
OUString tag_SignatureProperty(TAG_SIGNATUREPROPERTY);
OUString tag_Date(TAG_DATE);
OUString tag_Description(TAG_DESCRIPTION);
const SignatureReferenceInformations& vReferenceInfors = signatureInfo.vSignatureReferenceInfors;
SvXMLAttributeList *pAttributeList;
......@@ -944,6 +946,29 @@ void XSecController::exportSignature(
}
xDocumentHandler->endElement( tag_SignatureProperty );
}
// Write signature description.
if (!signatureInfo.ouDescription.isEmpty())
{
// SignatureProperty element.
pAttributeList = new SvXMLAttributeList();
pAttributeList->AddAttribute(ATTR_ID, signatureInfo.ouDescriptionPropertyId);
pAttributeList->AddAttribute(ATTR_TARGET, CHAR_FRAGMENT + signatureInfo.ouSignatureId);
xDocumentHandler->startElement(tag_SignatureProperty, uno::Reference<xml::sax::XAttributeList>(pAttributeList));
{
// Description element.
pAttributeList = new SvXMLAttributeList();
pAttributeList->AddAttribute(ATTR_XMLNS ":" NSTAG_DC, NS_DC);
xDocumentHandler->startElement(NSTAG_DC ":" + tag_Description, uno::Reference<xml::sax::XAttributeList>(pAttributeList));
xDocumentHandler->characters(signatureInfo.ouDescription);
xDocumentHandler->endElement(NSTAG_DC ":" + tag_Description);
}
xDocumentHandler->endElement(tag_SignatureProperty);
}
xDocumentHandler->endElement( tag_SignatureProperties );
}
xDocumentHandler->endElement( tag_Object );
......
......@@ -79,7 +79,7 @@
#define TAG_SIGNATUREPROPERTY "SignatureProperty"
#define TAG_TIMESTAMP "timestamp"
#define TAG_DATE "date"
//#define TAG_TIME "time"
#define TAG_DESCRIPTION "description"
#define ATTR_XMLNS "xmlns"
#define ATTR_ALGORITHM "Algorithm"
......@@ -450,6 +450,7 @@ public:
void setDate(
sal_Int32 nSecurityId,
const ::com::sun::star::util::DateTime& rDateTime );
void setDescription(sal_Int32 nSecurityId, const OUString& rDescription);
bool WriteSignature(
......
......@@ -258,6 +258,23 @@ void XSecController::setDate(
}
}
void XSecController::setDescription(sal_Int32 nSecurityId, const OUString& rDescription)
{
int nIndex = findSignatureInfor(nSecurityId);
if (nIndex == -1)
{
InternalSignatureInformation aInformation(nSecurityId, nullptr);
aInformation.signatureInfor.ouDescription = rDescription;
m_vInternalSignatureInformations.push_back(aInformation);
}
else
{
SignatureInformation& rInformation = m_vInternalSignatureInformations[nIndex].signatureInfor;
rInformation.ouDescription = rDescription;
}
}
bool XSecController::WriteSignature(
const cssu::Reference<cssxs::XDocumentHandler>& xDocumentHandler )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment