1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: biginteger.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include <xmlsecurity/biginteger.hxx>
36 #include <sal/types.h>
37 //For reasons that escape me, this is what xmlsec does when size_t is not 4
38 #if SAL_TYPES_SIZEOFPOINTER != 4
39 # define XMLSEC_NO_SIZE_T
41 #include <xmlsec/xmlsec.h>
42 #include <xmlsec/bn.h>
43 #include <com/sun/star/uno/Sequence.hxx>
45 using namespace ::com::sun::star::uno
;
46 using ::rtl::OUString
;
48 Sequence
< sal_Int8
> numericStringToBigInteger ( OUString numeral
)
50 if( numeral
.getStr() != NULL
)
53 const xmlSecByte
* bnInteger
;
57 rtl::OString onumeral
= rtl::OUStringToOString( numeral
, RTL_TEXTENCODING_ASCII_US
) ;
59 chNumeral
= xmlStrndup( ( const xmlChar
* )onumeral
.getStr(), ( int )onumeral
.getLength() ) ;
61 if( xmlSecBnInitialize( &bn
, 0 ) < 0 ) {
62 xmlFree( chNumeral
) ;
63 return Sequence
< sal_Int8
>();
66 if( xmlSecBnFromDecString( &bn
, chNumeral
) < 0 ) {
67 xmlFree( chNumeral
) ;
68 xmlSecBnFinalize( &bn
) ;
69 return Sequence
< sal_Int8
>();
72 xmlFree( chNumeral
) ;
74 length
= xmlSecBnGetSize( &bn
) ;
76 xmlSecBnFinalize( &bn
) ;
77 return Sequence
< sal_Int8
>();
80 bnInteger
= xmlSecBnGetData( &bn
) ;
81 if( bnInteger
== NULL
) {
82 xmlSecBnFinalize( &bn
) ;
83 return Sequence
< sal_Int8
>();
86 Sequence
< sal_Int8
> integer( length
) ;
87 for( unsigned int i
= 0 ; i
< length
; i
++ )
89 integer
[i
] = *( bnInteger
+ i
) ;
92 xmlSecBnFinalize( &bn
) ;
96 return Sequence
< sal_Int8
>();
99 OUString
bigIntegerToNumericString ( Sequence
< sal_Int8
> integer
)
103 if( integer
.getLength() ) {
107 if( xmlSecBnInitialize( &bn
, 0 ) < 0 )
110 if( xmlSecBnSetData( &bn
, ( const unsigned char* )&integer
[0], integer
.getLength() ) < 0 ) {
111 xmlSecBnFinalize( &bn
) ;
115 chNumeral
= xmlSecBnToDecString( &bn
) ;
116 if( chNumeral
== NULL
) {
117 xmlSecBnFinalize( &bn
) ;
121 aRet
= OUString::createFromAscii( ( const char* )chNumeral
) ;
123 xmlSecBnFinalize( &bn
) ;
124 xmlFree( chNumeral
) ;