Debian Codegraph @

xmlsecurity/source/xmlsec/xmlsec_init.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10 #include <sal/config.h>
11
12 #include <xmlsec/xmlsec_init.hxx>
13
14 #include <xmlsec/xmlsec.h>
15 #include <com/sun/star/uno/RuntimeException.hpp>
16 #include <xmlsec/xmlstreamio.hxx>
17 #ifdef XMLSEC_CRYPTO_MSCRYPTO
18 #include <xmlsec/mscng/crypto.h>
19 #endif
20 #ifdef XMLSEC_CRYPTO_NSS
21 #include <xmlsec/nss/crypto.h>
22 #endif
23
24 using namespace css::uno;
25
26 XSECXMLSEC_DLLPUBLIC void initXmlSec()
27 {
28 //Init xmlsec library
29 if( xmlSecInit() < 0 ) {
30 throw RuntimeException(u"Failed to initialize XML Security (xmlsec) library"_ustr) ;
31 }
32
33 //Init xmlsec crypto engine library
34 #ifdef XMLSEC_CRYPTO_MSCRYPTO
35 if( xmlSecMSCngInit() < 0 ) {
36 xmlSecShutdown();
37 throw RuntimeException("Failed to initialize XML Security (xmlsec) for Microsoft crypto engine library");
38 }
39 #endif
40 #ifdef XMLSEC_CRYPTO_NSS
41 if( xmlSecNssInit() < 0 ) {
42 xmlSecShutdown();
43 throw RuntimeException(u"Failed to Initialize XML Security (xmlsec) NSS crypto engine library"_ustr);
44 }
45 #endif
46
47 //Enable external stream handlers
48 if( xmlEnableStreamInputCallbacks() < 0 ) {
49 #ifdef XMLSEC_CRYPTO_MSCRYPTO
50 xmlSecMSCngShutdown();
51 #endif
52 #ifdef XMLSEC_CRYPTO_NSS
53 xmlSecNssShutdown();
54 #endif
55 xmlSecShutdown() ;
56 throw RuntimeException(u"Failed to Initialize XML Security (xmlsec) NSS crypto engine library"_ustr) ;
57 }
58 }
59
60 XSECXMLSEC_DLLPUBLIC void deInitXmlSec()
61 {
62 xmlDisableStreamInputCallbacks();
63 #ifdef XMLSEC_CRYPTO_MSCRYPTO
64 xmlSecMSCngShutdown();
65 #endif
66 #ifdef XMLSEC_CRYPTO_NSS
67 xmlSecNssShutdown();
68 #endif
69 xmlSecShutdown();
70 }
71
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */