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 <sal/types.h>
24 : //For reasons that escape me, this is what xmlsec does when size_t is not 4
25 : #if SAL_TYPES_SIZEOFPOINTER != 4
26 : # define XMLSEC_NO_SIZE_T
27 : #endif
28 : #include <xmlsec/xmlsec.h>
29 : #include <xmlsec/bn.h>
30 : #include <com/sun/star/uno/Sequence.hxx>
31 :
32 : using namespace ::com::sun::star::uno ;
33 : using ::rtl::OUString ;
34 :
35 0 : Sequence< sal_Int8 > numericStringToBigInteger ( OUString numeral )
36 : {
37 0 : if( numeral.getStr() != NULL )
38 : {
39 : xmlChar* chNumeral ;
40 : const xmlSecByte* bnInteger ;
41 : xmlSecSize length ;
42 : xmlSecBn bn ;
43 :
44 0 : rtl::OString onumeral = rtl::OUStringToOString( numeral , RTL_TEXTENCODING_ASCII_US ) ;
45 :
46 0 : chNumeral = xmlStrndup( ( const xmlChar* )onumeral.getStr(), ( int )onumeral.getLength() ) ;
47 :
48 0 : if( xmlSecBnInitialize( &bn, 0 ) < 0 ) {
49 0 : xmlFree( chNumeral ) ;
50 0 : return Sequence< sal_Int8 >();
51 : }
52 :
53 0 : if( xmlSecBnFromDecString( &bn, chNumeral ) < 0 ) {
54 0 : xmlFree( chNumeral ) ;
55 0 : xmlSecBnFinalize( &bn ) ;
56 0 : return Sequence< sal_Int8 >();
57 : }
58 :
59 0 : xmlFree( chNumeral ) ;
60 :
61 0 : length = xmlSecBnGetSize( &bn ) ;
62 0 : if( length <= 0 ) {
63 0 : xmlSecBnFinalize( &bn ) ;
64 0 : return Sequence< sal_Int8 >();
65 : }
66 :
67 0 : bnInteger = xmlSecBnGetData( &bn ) ;
68 0 : if( bnInteger == NULL ) {
69 0 : xmlSecBnFinalize( &bn ) ;
70 0 : return Sequence< sal_Int8 >();
71 : }
72 :
73 0 : Sequence< sal_Int8 > integer( length ) ;
74 0 : for( unsigned int i = 0 ; i < length ; i ++ )
75 : {
76 0 : integer[i] = *( bnInteger + i ) ;
77 : }
78 :
79 0 : xmlSecBnFinalize( &bn ) ;
80 0 : return integer ;
81 : }
82 :
83 0 : return Sequence< sal_Int8 >();
84 : }
85 :
86 0 : OUString bigIntegerToNumericString ( Sequence< sal_Int8 > integer )
87 : {
88 0 : OUString aRet ;
89 :
90 0 : if( integer.getLength() ) {
91 : xmlSecBn bn ;
92 : xmlChar* chNumeral ;
93 :
94 0 : if( xmlSecBnInitialize( &bn, 0 ) < 0 )
95 : return aRet ;
96 :
97 0 : if( xmlSecBnSetData( &bn, ( const unsigned char* )&integer[0], integer.getLength() ) < 0 ) {
98 0 : xmlSecBnFinalize( &bn ) ;
99 : return aRet ;
100 : }
101 :
102 0 : chNumeral = xmlSecBnToDecString( &bn ) ;
103 0 : if( chNumeral == NULL ) {
104 0 : xmlSecBnFinalize( &bn ) ;
105 : return aRet ;
106 : }
107 :
108 0 : aRet = OUString::createFromAscii( ( const char* )chNumeral ) ;
109 :
110 0 : xmlSecBnFinalize( &bn ) ;
111 0 : xmlFree( chNumeral ) ;
112 : }
113 :
114 0 : return aRet ;
115 : }
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|