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 .
21 #include <biginteger.hxx>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <xmlsec/xmlsec.h>
25 #include <xmlsec/bn.h>
27 #include <comphelper/sequence.hxx>
29 using namespace ::com::sun::star::uno
;
33 Sequence
< sal_Int8
> numericStringToBigInteger ( std::u16string_view numeral
)
36 const xmlSecByte
* bnInteger
;
40 OString onumeral
= OUStringToOString( numeral
, RTL_TEXTENCODING_ASCII_US
) ;
42 chNumeral
= xmlStrndup( reinterpret_cast<const xmlChar
*>(onumeral
.getStr()), static_cast<int>(onumeral
.getLength()) ) ;
44 if( xmlSecBnInitialize( &bn
, 0 ) < 0 ) {
45 xmlFree( chNumeral
) ;
46 return Sequence
< sal_Int8
>();
49 if( xmlSecBnFromDecString( &bn
, chNumeral
) < 0 ) {
50 xmlFree( chNumeral
) ;
51 xmlSecBnFinalize( &bn
) ;
52 return Sequence
< sal_Int8
>();
55 xmlFree( chNumeral
) ;
57 length
= xmlSecBnGetSize( &bn
) ;
59 xmlSecBnFinalize( &bn
) ;
60 return Sequence
< sal_Int8
>();
63 bnInteger
= xmlSecBnGetData( &bn
) ;
64 if( bnInteger
== nullptr ) {
65 xmlSecBnFinalize( &bn
) ;
66 return Sequence
< sal_Int8
>();
69 Sequence
< sal_Int8
> integer
= comphelper::arrayToSequence
<sal_Int8
>(bnInteger
, length
);
71 xmlSecBnFinalize( &bn
) ;
75 OUString
bigIntegerToNumericString ( const Sequence
< sal_Int8
>& integer
)
79 if( integer
.hasElements() ) {
83 if( xmlSecBnInitialize( &bn
, 0 ) < 0 )
86 if( xmlSecBnSetData( &bn
, reinterpret_cast<const unsigned char*>(integer
.getConstArray()), integer
.getLength() ) < 0 ) {
87 xmlSecBnFinalize( &bn
) ;
91 chNumeral
= xmlSecBnToDecString( &bn
) ;
92 if( chNumeral
== nullptr ) {
93 xmlSecBnFinalize( &bn
) ;
97 aRet
= OUString::createFromAscii( reinterpret_cast<char*>(chNumeral
) ) ;
99 xmlSecBnFinalize( &bn
) ;
100 xmlFree( chNumeral
) ;
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */