bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / svl / cryptosign.hxx
blob61905360a1b9867fc0721f88b8ede49025453b48
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/types.h>
12 #include <vector>
14 #include <rtl/strbuf.hxx>
15 #include <rtl/ustring.hxx>
17 #include <com/sun/star/uno/Reference.hxx>
19 #include <svl/svldllapi.h>
21 namespace com {
22 namespace sun {
23 namespace star {
24 namespace security {
25 class XCertificate; }
26 }}}
28 class SvStream;
29 struct SignatureInformation;
31 namespace svl {
33 namespace crypto {
35 /// Converts a hex-encoded string into a byte array.
36 SVL_DLLPUBLIC std::vector<unsigned char> DecodeHexString(const OString& rHex);
38 /// Helper to cryptographically sign and verify
39 /// arbitrary data blocks.
40 class SVL_DLLPUBLIC Signing
42 public:
44 Signing(const css::uno::Reference<css::security::XCertificate>& xCertificate) :
45 m_xCertificate(xCertificate)
49 /// Add a range to sign.
50 /// Note: for efficiency this takes a naked pointer, which must remain valid
51 /// until this object is discarded.
52 void AddDataRange(const void* pData, sal_Int32 size)
54 m_dataBlocks.emplace_back(pData, size);
57 void SetSignTSA(const OUString& tsa) { m_aSignTSA = tsa; }
58 void SetSignPassword(const OUString& password) { m_aSignPassword = password; }
60 /// Signs one or more data blocks (as a single, contiguous, array).
61 /// Returns the signature (in PKCS#7 format) as string (hex).
62 bool Sign(OStringBuffer& rCMSHexBuffer);
64 /// Verify and get Signature Information given a byte array.
65 static bool Verify(const std::vector<unsigned char>& aData,
66 const bool bNonDetached,
67 const std::vector<unsigned char>& aSignature,
68 SignatureInformation& rInformation);
70 /// Verify and get Signature Information given a signature and stream.
71 static bool Verify(SvStream& rStream,
72 const std::vector<std::pair<size_t, size_t>>& aByteRanges,
73 const bool bNonDetached,
74 const std::vector<unsigned char>& aSignature,
75 SignatureInformation& rInformation);
77 private:
78 /// The certificate to use for signing.
79 const css::uno::Reference<css::security::XCertificate> m_xCertificate;
81 /// Data blocks (pointer-size pairs).
82 std::vector<std::pair<const void*, sal_Int32>> m_dataBlocks;
83 OUString m_aSignTSA;
84 OUString m_aSignPassword;
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */