LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec - biginteger.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 42 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <xmlsecurity/biginteger.hxx>
      22             : 
      23             : #include "xmlsecurity/xmlsec-wrapper.h"
      24             : #include <com/sun/star/uno/Sequence.hxx>
      25             : 
      26             : using namespace ::com::sun::star::uno ;
      27             : 
      28           0 : Sequence< sal_Int8 > numericStringToBigInteger ( const OUString& numeral )
      29             : {
      30           0 :     if( numeral.getStr() != NULL )
      31             :     {
      32             :         xmlChar* chNumeral ;
      33             :         const xmlSecByte* bnInteger ;
      34             :         xmlSecSize length ;
      35             :         xmlSecBn bn ;
      36             : 
      37           0 :         OString onumeral = OUStringToOString( numeral , RTL_TEXTENCODING_ASCII_US ) ;
      38             : 
      39           0 :         chNumeral = xmlStrndup( reinterpret_cast<const xmlChar*>(onumeral.getStr()), ( int )onumeral.getLength() ) ;
      40             : 
      41           0 :         if( xmlSecBnInitialize( &bn, 0 ) < 0 ) {
      42           0 :             xmlFree( chNumeral ) ;
      43           0 :             return Sequence< sal_Int8 >();
      44             :         }
      45             : 
      46           0 :         if( xmlSecBnFromDecString( &bn, chNumeral ) < 0 ) {
      47           0 :             xmlFree( chNumeral ) ;
      48           0 :             xmlSecBnFinalize( &bn ) ;
      49           0 :             return Sequence< sal_Int8 >();
      50             :         }
      51             : 
      52           0 :         xmlFree( chNumeral ) ;
      53             : 
      54           0 :         length = xmlSecBnGetSize( &bn ) ;
      55           0 :         if( length <= 0 ) {
      56           0 :             xmlSecBnFinalize( &bn ) ;
      57           0 :             return Sequence< sal_Int8 >();
      58             :         }
      59             : 
      60           0 :         bnInteger = xmlSecBnGetData( &bn ) ;
      61           0 :         if( bnInteger == NULL ) {
      62           0 :             xmlSecBnFinalize( &bn ) ;
      63           0 :             return Sequence< sal_Int8 >();
      64             :         }
      65             : 
      66           0 :         Sequence< sal_Int8 > integer( length ) ;
      67           0 :         for( unsigned int i = 0 ; i < length ; i ++ )
      68             :         {
      69           0 :             integer[i] = *( bnInteger + i ) ;
      70             :         }
      71             : 
      72           0 :         xmlSecBnFinalize( &bn ) ;
      73           0 :         return integer ;
      74             :     }
      75             : 
      76           0 :     return Sequence< sal_Int8 >();
      77             : }
      78             : 
      79           0 : OUString bigIntegerToNumericString ( const Sequence< sal_Int8 >& integer )
      80             : {
      81           0 :     OUString aRet ;
      82             : 
      83           0 :     if( integer.getLength() ) {
      84             :         xmlSecBn bn ;
      85             :         xmlChar* chNumeral ;
      86             : 
      87           0 :         if( xmlSecBnInitialize( &bn, 0 ) < 0 )
      88           0 :             return aRet ;
      89             : 
      90           0 :         if( xmlSecBnSetData( &bn, reinterpret_cast<const unsigned char*>(integer.getConstArray()), integer.getLength() ) < 0 ) {
      91           0 :             xmlSecBnFinalize( &bn ) ;
      92           0 :             return aRet ;
      93             :         }
      94             : 
      95           0 :         chNumeral = xmlSecBnToDecString( &bn ) ;
      96           0 :         if( chNumeral == NULL ) {
      97           0 :             xmlSecBnFinalize( &bn ) ;
      98           0 :             return aRet ;
      99             :         }
     100             : 
     101           0 :         aRet = OUString::createFromAscii( reinterpret_cast<char*>(chNumeral) ) ;
     102             : 
     103           0 :         xmlSecBnFinalize( &bn ) ;
     104           0 :         xmlFree( chNumeral ) ;
     105             :     }
     106             : 
     107           0 :     return aRet ;
     108             : }
     109             : 
     110             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11