bump product version to 4.1.6.2
[LibreOffice.git] / xmlsecurity / source / component / certificatecontainer.cxx
blobf96f7663e202ef26fbbcdbe9c8caa8e7cc70538a
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>
22 #include <sal/config.h>
24 using namespace ::com::sun::star;
25 using namespace ::com::sun::star::lang;
26 using namespace ::com::sun::star::uno;
28 sal_Bool
29 CertificateContainer::searchMap( const OUString & url, const OUString & certificate_name, Map &_certMap )
31 Map::iterator p = _certMap.find(url);
33 ::sal_Bool ret = sal_False;
35 while( p != _certMap.end() )
37 ret = (sal_Bool) (*p).second.equals(certificate_name);
38 if( ret )
39 break;
40 ++p;
43 return ret;
45 // -------------------------------------------------------------------
47 sal_Bool
48 CertificateContainer::isTemporaryCertificate ( const OUString & url, const OUString & certificate_name )
49 throw(::com::sun::star::uno::RuntimeException)
51 return searchMap( url, certificate_name, certMap);
54 // -------------------------------------------------------------------
56 sal_Bool
57 CertificateContainer::isCertificateTrust ( const OUString & url, const OUString & certificate_name )
58 throw(::com::sun::star::uno::RuntimeException)
60 return searchMap( url, certificate_name, certTrustMap);
63 // -------------------------------------------------------------------
64 sal_Bool
65 CertificateContainer::addCertificate( const OUString & url, const OUString & certificate_name, ::sal_Bool trust )
66 throw(::com::sun::star::uno::RuntimeException)
68 certMap.insert( Map::value_type( url, certificate_name ) );
70 //remember that the cert is trusted
71 if (trust)
72 certTrustMap.insert( Map::value_type( url, certificate_name ) );
74 return true;
77 //-------------------------------------------------------------------------
78 ::security::CertificateContainerStatus
79 CertificateContainer::hasCertificate( const OUString & url, const OUString & certificate_name ) throw(::com::sun::star::uno::RuntimeException)
81 if ( isTemporaryCertificate( url, certificate_name ) )
83 if ( isCertificateTrust( url, certificate_name ) )
84 return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED );
85 else
86 return security::CertificateContainerStatus_UNTRUSTED;
87 } else
89 return security::CertificateContainerStatus_NOCERT;
92 //-------------------------------------------------------------------------
94 OUString SAL_CALL
95 CertificateContainer::getImplementationName( )
96 throw(::com::sun::star::uno::RuntimeException)
98 return impl_getStaticImplementationName();
101 //-------------------------------------------------------------------------
103 sal_Bool SAL_CALL
104 CertificateContainer::supportsService( const OUString& ServiceName )
105 throw(::com::sun::star::uno::RuntimeException)
107 if ( ServiceName.compareToAscii("com.sun.star.security.CertificateContainer") == 0 )
108 return sal_True;
109 else
110 return sal_False;
113 //-------------------------------------------------------------------------
115 Sequence< OUString > SAL_CALL
116 CertificateContainer::getSupportedServiceNames( )
117 throw(::com::sun::star::uno::RuntimeException)
119 return impl_getStaticSupportedServiceNames();
122 //-------------------------------------------------------------------------
124 Sequence< OUString > SAL_CALL
125 CertificateContainer::impl_getStaticSupportedServiceNames( )
126 throw(::com::sun::star::uno::RuntimeException)
128 Sequence< OUString > aRet(1);
129 *aRet.getArray() = OUString("com.sun.star.security.CertificateContainer");
130 return aRet;
133 //-------------------------------------------------------------------------
135 OUString SAL_CALL
136 CertificateContainer::impl_getStaticImplementationName()
137 throw(::com::sun::star::uno::RuntimeException)
139 return OUString("com.sun.star.security.CertificateContainer");
142 //-------------------------------------------------------------------------
144 Reference< XInterface > SAL_CALL CertificateContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager )
145 throw( RuntimeException )
147 return Reference< XInterface >( *new CertificateContainer( xServiceManager ) );
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */