Bump version to 5.0-14
[LibreOffice.git] / xmlsecurity / source / xmlsec / biginteger.cxx
blobe79bc51577ef099b5ea44d2cdc2708c0a7a8ca64
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 .
21 #include <xmlsecurity/biginteger.hxx>
23 #include "xmlsecurity/xmlsec-wrapper.h"
24 #include <com/sun/star/uno/Sequence.hxx>
26 using namespace ::com::sun::star::uno ;
28 Sequence< sal_Int8 > numericStringToBigInteger ( const OUString& numeral )
30 if( numeral.getStr() != NULL )
32 xmlChar* chNumeral ;
33 const xmlSecByte* bnInteger ;
34 xmlSecSize length ;
35 xmlSecBn bn ;
37 OString onumeral = OUStringToOString( numeral , RTL_TEXTENCODING_ASCII_US ) ;
39 chNumeral = xmlStrndup( reinterpret_cast<const xmlChar*>(onumeral.getStr()), ( int )onumeral.getLength() ) ;
41 if( xmlSecBnInitialize( &bn, 0 ) < 0 ) {
42 xmlFree( chNumeral ) ;
43 return Sequence< sal_Int8 >();
46 if( xmlSecBnFromDecString( &bn, chNumeral ) < 0 ) {
47 xmlFree( chNumeral ) ;
48 xmlSecBnFinalize( &bn ) ;
49 return Sequence< sal_Int8 >();
52 xmlFree( chNumeral ) ;
54 length = xmlSecBnGetSize( &bn ) ;
55 if( length <= 0 ) {
56 xmlSecBnFinalize( &bn ) ;
57 return Sequence< sal_Int8 >();
60 bnInteger = xmlSecBnGetData( &bn ) ;
61 if( bnInteger == NULL ) {
62 xmlSecBnFinalize( &bn ) ;
63 return Sequence< sal_Int8 >();
66 Sequence< sal_Int8 > integer( length ) ;
67 for( unsigned int i = 0 ; i < length ; i ++ )
69 integer[i] = *( bnInteger + i ) ;
72 xmlSecBnFinalize( &bn ) ;
73 return integer ;
76 return Sequence< sal_Int8 >();
79 OUString bigIntegerToNumericString ( const Sequence< sal_Int8 >& integer )
81 OUString aRet ;
83 if( integer.getLength() ) {
84 xmlSecBn bn ;
85 xmlChar* chNumeral ;
87 if( xmlSecBnInitialize( &bn, 0 ) < 0 )
88 return aRet ;
90 if( xmlSecBnSetData( &bn, reinterpret_cast<const unsigned char*>(integer.getConstArray()), integer.getLength() ) < 0 ) {
91 xmlSecBnFinalize( &bn ) ;
92 return aRet ;
95 chNumeral = xmlSecBnToDecString( &bn ) ;
96 if( chNumeral == NULL ) {
97 xmlSecBnFinalize( &bn ) ;
98 return aRet ;
101 aRet = OUString::createFromAscii( reinterpret_cast<char*>(chNumeral) ) ;
103 xmlSecBnFinalize( &bn ) ;
104 xmlFree( chNumeral ) ;
107 return aRet ;
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */