Bump version to 6.0-36
[LibreOffice.git] / xmlsecurity / source / component / certificatecontainer.cxx
blobac52bbf6fde1d587edebce60acd8f570edc64b20
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "certificatecontainer.hxx"
21 #include <cppuhelper/supportsservice.hxx>
23 #include <sal/config.h>
25 using namespace ::com::sun::star;
26 using namespace ::com::sun::star::lang;
27 using namespace ::com::sun::star::uno;
29 bool
30 CertificateContainer::searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap )
32 Map::iterator p = _certMap.find(url);
34 bool ret = false;
36 while( p != _certMap.end() )
38 ret = (*p).second == certificate_name;
39 if( ret )
40 break;
41 ++p;
44 return ret;
47 bool
48 CertificateContainer::isTemporaryCertificate ( const OUString & url, const OUString & certificate_name )
50 return searchMap( url, certificate_name, certMap);
53 bool
54 CertificateContainer::isCertificateTrust ( const OUString & url, const OUString & certificate_name )
56 return searchMap( url, certificate_name, certTrustMap);
59 sal_Bool
60 CertificateContainer::addCertificate( const OUString & url, const OUString & certificate_name, sal_Bool trust )
62 certMap.emplace( url, certificate_name );
64 //remember that the cert is trusted
65 if (trust)
66 certTrustMap.emplace( url, certificate_name );
68 return true;
71 ::security::CertificateContainerStatus
72 CertificateContainer::hasCertificate( const OUString & url, const OUString & certificate_name )
74 if ( isTemporaryCertificate( url, certificate_name ) )
76 if ( isCertificateTrust( url, certificate_name ) )
77 return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED );
78 else
79 return security::CertificateContainerStatus_UNTRUSTED;
80 } else
82 return security::CertificateContainerStatus_NOCERT;
86 OUString SAL_CALL
87 CertificateContainer::getImplementationName( )
89 return impl_getStaticImplementationName();
92 sal_Bool SAL_CALL
93 CertificateContainer::supportsService( const OUString& ServiceName )
95 return cppu::supportsService( this, ServiceName );
98 Sequence< OUString > SAL_CALL
99 CertificateContainer::getSupportedServiceNames( )
101 return impl_getStaticSupportedServiceNames();
104 Sequence< OUString > SAL_CALL
105 CertificateContainer::impl_getStaticSupportedServiceNames( )
107 Sequence< OUString > aRet { "com.sun.star.security.CertificateContainer" };
108 return aRet;
111 OUString SAL_CALL
112 CertificateContainer::impl_getStaticImplementationName()
114 return OUString("com.sun.star.security.CertificateContainer");
117 Reference< XInterface > SAL_CALL CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
119 return Reference< XInterface >( *new CertificateContainer( xServiceManager ) );
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */