20#include <com/sun/star/embed/XStorage.hpp>
21#include <com/sun/star/embed/XTransactedObject.hpp>
22#include <com/sun/star/security/DocumentDigitalSignatures.hpp>
23#include <com/sun/star/io/IOException.hpp>
24#include <com/sun/star/io/XStream.hpp>
32 std::unique_ptr<SvStream> pStream(
37 uno::Reference<embed::XStorage> xWriteableZipStore;
43 catch (
const io::IOException&)
49 uno::Reference<security::XDocumentDigitalSignatures> xSigner(
50 security::DocumentDigitalSignatures::createWithVersionAndValidSignature(
56 uno::Reference<embed::XStorage> xMetaInf;
57 if (xWriteableZipStore.is() && xWriteableZipStore->hasByName(
"META-INF"))
59 xMetaInf = xWriteableZipStore->openStorageElement(
"META-INF",
60 embed::ElementModes::READWRITE);
62 throw uno::RuntimeException();
66 uno::Reference<embed::XStorage> xStorage
71 uno::Reference<io::XStream>
xStream;
73 xMetaInf->openStreamElement(xSigner->getDocumentContentSignatureDefaultStreamName(),
74 embed::ElementModes::READWRITE),
76 bool bSuccess = xSigner->signDocumentWithCertificate(rxCertificate, xStorage,
xStream);
79 uno::Reference<embed::XTransactedObject> xTransact(xMetaInf, uno::UNO_QUERY_THROW);
81 xTransact.set(xWriteableZipStore, uno::UNO_QUERY_THROW);
86 else if (xWriteableZipStore.is())
88 uno::Reference<embed::XStorage> xStorage
93 uno::Reference<io::XStream>
xStream;
96 bool bSuccess = xSigner->signDocumentWithCertificate(rxCertificate, xStorage,
xStream);
100 uno::Reference<embed::XTransactedObject> xTransact(xWriteableZipStore,
101 uno::UNO_QUERY_THROW);
109 bResult = xSigner->signDocumentWithCertificate(
110 rxCertificate, uno::Reference<embed::XStorage>(), xInputStream);
113 catch (
const uno::Exception&)
static OUString GetODFVersionFromStorage(const css::uno::Reference< css::embed::XStorage > &xStorage)
static css::uno::Reference< css::embed::XStorage > GetStorageOfFormatFromStream(const OUString &aFormat, const css::uno::Reference< css::io::XStream > &xStream, sal_Int32 nStorageMode=css::embed::ElementModes::READWRITE, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >(), bool bRepairStorage=false)
bool signDocument(css::uno::Reference< css::security::XCertificate > const &rxCertificate)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
Reference< XComponentContext > getProcessComponentContext()
constexpr OUStringLiteral ZIP_STORAGE_FORMAT_STRING