1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
30 CertificateContainer::searchMap( const OUString
& url
, const OUString
& certificate_name
, Map
&_certMap
)
32 Map::iterator p
= _certMap
.find(url
);
36 while( p
!= _certMap
.end() )
38 ret
= (*p
).second
.equals(certificate_name
);
48 CertificateContainer::isTemporaryCertificate ( const OUString
& url
, const OUString
& certificate_name
)
49 throw(::com::sun::star::uno::RuntimeException
)
51 return searchMap( url
, certificate_name
, certMap
);
55 CertificateContainer::isCertificateTrust ( const OUString
& url
, const OUString
& certificate_name
)
56 throw(::com::sun::star::uno::RuntimeException
)
58 return searchMap( url
, certificate_name
, certTrustMap
);
62 CertificateContainer::addCertificate( const OUString
& url
, const OUString
& certificate_name
, sal_Bool trust
)
63 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
65 certMap
.insert( Map::value_type( url
, certificate_name
) );
67 //remember that the cert is trusted
69 certTrustMap
.insert( Map::value_type( url
, certificate_name
) );
74 ::security::CertificateContainerStatus
75 CertificateContainer::hasCertificate( const OUString
& url
, const OUString
& certificate_name
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
77 if ( isTemporaryCertificate( url
, certificate_name
) )
79 if ( isCertificateTrust( url
, certificate_name
) )
80 return security::CertificateContainerStatus( security::CertificateContainerStatus_TRUSTED
);
82 return security::CertificateContainerStatus_UNTRUSTED
;
85 return security::CertificateContainerStatus_NOCERT
;
90 CertificateContainer::getImplementationName( )
91 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
93 return impl_getStaticImplementationName();
97 CertificateContainer::supportsService( const OUString
& ServiceName
)
98 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
100 return cppu::supportsService( this, ServiceName
);
103 Sequence
< OUString
> SAL_CALL
104 CertificateContainer::getSupportedServiceNames( )
105 throw(::com::sun::star::uno::RuntimeException
, std::exception
)
107 return impl_getStaticSupportedServiceNames();
110 Sequence
< OUString
> SAL_CALL
111 CertificateContainer::impl_getStaticSupportedServiceNames( )
112 throw(::com::sun::star::uno::RuntimeException
)
114 Sequence
< OUString
> aRet(1);
115 aRet
[0] = "com.sun.star.security.CertificateContainer";
120 CertificateContainer::impl_getStaticImplementationName()
121 throw(::com::sun::star::uno::RuntimeException
)
123 return OUString("com.sun.star.security.CertificateContainer");
126 Reference
< XInterface
> SAL_CALL
CertificateContainer::impl_createInstance( const Reference
< XMultiServiceFactory
>& xServiceManager
)
127 throw( RuntimeException
)
129 return Reference
< XInterface
>( *new CertificateContainer( xServiceManager
) );
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */