summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-07-14 22:21:00 -0400
committerAshod Nakashian <ashnakash@gmail.com>2017-07-15 20:52:39 +0200
commit522d211764725b19b7975f500f315444601cdf6b (patch)
tree5884a9201dbefa6a1c8a054591f2f9407f079751 /include
parentec22318ccd93fffe60792a14c6d50c1672ef9428 (diff)
svl: move byte-array signing from vcl
Signing a generic byte-array can (and will be) used by more than the existing PDF signing code, hence the move into comphelper from vcl and ourside of the PDF-specific logic. Change-Id: I7257b5218c6ba37960c6a013746eb387917a23a4 Reviewed-on: https://gerrit.libreoffice.org/39717 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/sal/log-areas.dox1
-rw-r--r--include/svl/cryptosign.hxx71
2 files changed, 72 insertions, 0 deletions
diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index 63f1438d0211..cad1e42ad0a4 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -342,6 +342,7 @@ certain functionality.
@section svl
@li @c svl
+@li @c svl.crypto
@li @c svl.items
@li @c svl.numbers
diff --git a/include/svl/cryptosign.hxx b/include/svl/cryptosign.hxx
new file mode 100644
index 000000000000..db0abc9f1480
--- /dev/null
+++ b/include/svl/cryptosign.hxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <config_features.h>
+#include <sal/types.h>
+
+#include <memory>
+#include <vector>
+
+#include <rtl/strbuf.hxx>
+#include <svl/svldllapi.h>
+#include "com/sun/star/uno/Reference.hxx"
+
+namespace com {
+namespace sun {
+namespace star {
+namespace security {
+ class XCertificate; }
+}}}
+
+namespace svl {
+
+namespace crypto {
+
+/// Helper to cryptographically sign and verify
+/// arbitrary data blocks.
+class SVL_DLLPUBLIC Signing
+{
+public:
+
+ Signing(const css::uno::Reference<css::security::XCertificate>& xCertificate) :
+ m_xCertificate(xCertificate)
+ {
+ }
+
+ /// Add a range to sign.
+ /// Note: for efficiency this takes a naked pointer, which must remain valid
+ /// until this object is discarded.
+ void AddDataRange(void* pData, sal_Int32 size)
+ {
+ m_dataBlocks.emplace_back(pData, size);
+ }
+
+ void SetSignTSA(const OUString& tsa) { m_aSignTSA = tsa; }
+ void SetSignPassword(const OUString& password) { m_aSignPassword = password;; }
+
+ /// Signs one or more data blocks (as a single, contiguous, array).
+ /// Returns the signature (in PKCS#7 format) as string (hex).
+ bool Sign(OStringBuffer& rCMSHexBuffer);
+
+private:
+ /// The certificate to use for signing.
+ const css::uno::Reference<css::security::XCertificate> m_xCertificate;
+
+ /// Data blocks (pointer-size pairs).
+ std::vector<std::pair<void*, sal_Int32>> m_dataBlocks;
+ OUString m_aSignTSA;
+ OUString m_aSignPassword;
+};
+
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+