/* -*- 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 #include #include #include #include #include #include #include #include namespace com { namespace sun { namespace star { namespace security { class XCertificate; } }}} class SvStream; namespace svl { namespace crypto { /// Converts a hex-encoded string into a byte array. SVL_DLLPUBLIC std::vector DecodeHexString(const OString& rHex); /// Helper to cryptographically sign and verify /// arbitrary data blocks. class SVL_DLLPUBLIC Signing { public: Signing(const css::uno::Reference& 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(const 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); /// Verify and get Signature Information given a byte array. static bool Verify(const std::vector& aData, const bool bNonDetached, const std::vector& aSignature, SignatureInformation& rInformation); /// Verify and get Signature Information given a signature and stream. static bool Verify(SvStream& rStream, const std::vector>& aByteRanges, const bool bNonDetached, const std::vector& aSignature, SignatureInformation& rInformation); private: /// The certificate to use for signing. const css::uno::Reference m_xCertificate; /// Data blocks (pointer-size pairs). std::vector> m_dataBlocks; OUString m_aSignTSA; OUString m_aSignPassword; }; /// Decides if SVL_CRYPTO_MSCRYPTO uses the new CNG API or not. SVL_DLLPUBLIC bool isMSCng(); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */