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>
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
;
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
);
45 // -------------------------------------------------------------------
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 // -------------------------------------------------------------------
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 // -------------------------------------------------------------------
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
72 certTrustMap
.insert( Map::value_type( url
, certificate_name
) );
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
);
86 return security::CertificateContainerStatus_UNTRUSTED
;
89 return security::CertificateContainerStatus_NOCERT
;
92 //-------------------------------------------------------------------------
95 CertificateContainer::getImplementationName( )
96 throw(::com::sun::star::uno::RuntimeException
)
98 return impl_getStaticImplementationName();
101 //-------------------------------------------------------------------------
104 CertificateContainer::supportsService( const OUString
& ServiceName
)
105 throw(::com::sun::star::uno::RuntimeException
)
107 if ( ServiceName
.compareToAscii("com.sun.star.security.CertificateContainer") == 0 )
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");
133 //-------------------------------------------------------------------------
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: */