tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmlsecurity / source / xmlsec / biginteger.cxx
blob489b0ed5cf8368b6060e64816e43489671a7107b
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 <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 ;
31 namespace xmlsecurity
33 Sequence< sal_Int8 > numericStringToBigInteger ( std::u16string_view numeral )
35 xmlChar* chNumeral ;
36 const xmlSecByte* bnInteger ;
37 xmlSecSize length ;
38 xmlSecBn bn ;
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 ) ;
58 if( length <= 0 ) {
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 ) ;
72 return integer ;
75 OUString bigIntegerToNumericString ( const Sequence< sal_Int8 >& integer )
77 OUString aRet ;
79 if( integer.hasElements() ) {
80 xmlSecBn bn ;
81 xmlChar* chNumeral ;
83 if( xmlSecBnInitialize( &bn, 0 ) < 0 )
84 return aRet ;
86 if( xmlSecBnSetData( &bn, reinterpret_cast<const unsigned char*>(integer.getConstArray()), integer.getLength() ) < 0 ) {
87 xmlSecBnFinalize( &bn ) ;
88 return aRet ;
91 chNumeral = xmlSecBnToDecString( &bn ) ;
92 if( chNumeral == nullptr ) {
93 xmlSecBnFinalize( &bn ) ;
94 return aRet ;
97 aRet = OUString::createFromAscii( reinterpret_cast<char*>(chNumeral) ) ;
99 xmlSecBnFinalize( &bn ) ;
100 xmlFree( chNumeral ) ;
103 return aRet ;
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */