1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "oox/helper/openssl_wrapper.hxx"
25 #include "rtl/ustrbuf.hxx"
26 
27 #include <openssl/err.h>
28 
29 
30 namespace oox {
31 
32 // ============================================================================
33 
34 using namespace ::com::sun::star::uno;
35 
36 using ::rtl::OUString;
37 using ::rtl::OUStringBuffer;
38 
39 // ============================================================================
40 
error_cb(const char * message,size_t len,void * userData)41 static int error_cb( const char *message, size_t len, void *userData )
42 {
43     OUStringBuffer* buffer = (OUStringBuffer*) userData;
44     buffer->appendAscii( "\n    " );
45     // The message often ends in its own '\n', remove this:
46     if( len > 0 && message[ len - 1 ] == '\n' )
47         buffer->appendAscii( message, len - 1 );
48     else
49         buffer->appendAscii( message, len );
50     return 1;
51 }
52 
throwOpenSSLException(const char * prefix)53 void throwOpenSSLException( const char *prefix ) throw ( Exception )
54 {
55     OUStringBuffer buffer;
56     buffer.appendAscii( prefix );
57     ERR_print_errors_cb( error_cb, &buffer );
58     throw Exception( buffer.makeStringAndClear(), Reference< XInterface >() );
59 }
60 
61 // ============================================================================
62 
63 } // namespace oox
64