merge the formfield patch from ooo-build
[ooovba.git] / sal / qa / rtl / cipher / rtl_cipher.cxx
blob60c99f4fb2f2e6369e131e9a13303b176afc500a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_cipher.cxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
35 #include <cppunit/simpleheader.hxx>
36 #include <rtl/strbuf.hxx>
37 #include <rtl/cipher.h>
39 // -----------------------------------------------------------------------------
40 namespace rtl_cipher
43 rtl::OString createHex(sal_uInt8 *_pKeyBuffer, sal_uInt32 _nKeyLen)
45 // Create hex-value string from the value to keep the string size minimal
46 rtl::OStringBuffer aBuffer( _nKeyLen * 2 + 1 );
47 for ( sal_uInt32 i = 0; i < _nKeyLen; i++ )
49 sal_Int32 nValue = (sal_Int32)_pKeyBuffer[i];
50 if (nValue < 16) // maximul hex value for 1 byte
52 aBuffer.append( sal_Int32(0), 16 /* radix */ );
54 aBuffer.append( nValue, 16 /* radix */ );
57 return aBuffer.makeStringAndClear();
60 // -----------------------------------------------------------------------------
62 class create : public CppUnit::TestFixture
64 public:
65 // initialise your test code values here.
66 void setUp()
70 void tearDown()
74 void create_001()
76 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
77 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
78 rtl_cipher_destroy(aCipher);
80 void create_002()
82 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB);
83 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
85 void create_003()
87 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
88 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
89 rtl_cipher_destroy(aCipher);
91 void create_004()
93 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC);
94 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
96 void create_005()
98 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
99 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
100 rtl_cipher_destroy(aCipher);
102 void create_006()
104 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream);
105 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
107 void create_007()
109 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid);
110 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
112 void create_008()
114 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid);
115 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
118 // Change the following lines only, if you add, remove or rename
119 // member functions of the current class,
120 // because these macros are need by auto register mechanism.
122 CPPUNIT_TEST_SUITE(create);
123 CPPUNIT_TEST(create_001);
124 CPPUNIT_TEST(create_002);
125 CPPUNIT_TEST(create_003);
126 CPPUNIT_TEST(create_004);
127 CPPUNIT_TEST(create_005);
128 CPPUNIT_TEST(create_006);
129 CPPUNIT_TEST(create_007);
130 CPPUNIT_TEST(create_008);
131 CPPUNIT_TEST_SUITE_END();
132 }; // class create
134 // -----------------------------------------------------------------------------
135 class createBF : public CppUnit::TestFixture
137 public:
138 // initialise your test code values here.
139 void setUp()
143 void tearDown()
147 void createBF_001()
149 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
150 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
151 rtl_cipher_destroy(aCipher);
153 void createBF_002()
155 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC);
156 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
157 rtl_cipher_destroy(aCipher);
159 void createBF_003()
161 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream);
162 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
163 rtl_cipher_destroy(aCipher);
165 void createBF_004()
167 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid);
168 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
169 // rtl_cipher_destroy(aCipher);
171 // Change the following lines only, if you add, remove or rename
172 // member functions of the current class,
173 // because these macros are need by auto register mechanism.
175 CPPUNIT_TEST_SUITE(createBF);
176 CPPUNIT_TEST(createBF_001);
177 CPPUNIT_TEST(createBF_002);
178 CPPUNIT_TEST(createBF_003);
179 CPPUNIT_TEST(createBF_004);
180 CPPUNIT_TEST_SUITE_END();
181 }; // class createBF
182 // -----------------------------------------------------------------------------
183 class decode : public CppUnit::TestFixture
185 public:
186 // initialise your test code values here.
187 void setUp()
191 void tearDown()
195 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
197 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
198 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
200 sal_uInt32 nKeyLen = 16;
201 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
202 memset(pKeyBuffer, 0, nKeyLen);
203 pKeyBuffer[0] = _nKeyValue;
205 sal_uInt32 nArgLen = 16;
206 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
207 memset(pArgBuffer, 0, nArgLen);
208 pArgBuffer[0] = _nArgValue;
210 t_print(T_VERBOSE, " init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
211 t_print(T_VERBOSE, " init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
213 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
214 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
216 sal_uInt32 nPlainTextLen = 16;
217 sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
218 memset(pPlainTextBuffer, 0, nPlainTextLen);
219 strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
221 sal_uInt32 nCipherLen = 16;
222 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ];
223 memset(pCipherBuffer, 0, nCipherLen);
225 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
226 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
228 t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
229 t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
230 t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
231 t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
233 sal_uInt32 nPlainText2Len = 16;
234 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
235 memset(pPlainText2Buffer, 0, nPlainText2Len);
237 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
238 CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None);
240 // rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
241 // t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
242 // t_print(T_VERBOSE, " ascii: %s\n", sPlainText2Str.getStr());
244 // // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
246 // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
248 // CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
250 // delete [] pPlainText2Buffer;
252 // delete [] pCipherBuffer;
253 // delete [] pPlainTextBuffer;
255 // delete [] pArgBuffer;
256 // delete [] pKeyBuffer;
258 // rtl_cipher_destroy(aCipher);
261 void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
263 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
264 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
266 sal_uInt32 nKeyLen = 16;
267 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
268 memset(pKeyBuffer, 0, nKeyLen);
269 pKeyBuffer[0] = _nKeyValue;
271 sal_uInt32 nArgLen = 16;
272 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
273 memset(pArgBuffer, 0, nArgLen);
274 pArgBuffer[0] = _nArgValue;
276 t_print(T_VERBOSE, " init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
277 t_print(T_VERBOSE, " init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
279 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
280 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
282 sal_uInt32 nPlainTextLen = 16;
283 sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
284 memset(pPlainTextBuffer, 0, nPlainTextLen);
285 strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
287 sal_uInt32 nCipherLen = 16;
288 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ];
289 memset(pCipherBuffer, 0, nCipherLen);
291 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
292 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
294 t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
295 t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
296 t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
297 t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
299 sal_uInt32 nPlainText2Len = 16;
300 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
301 memset(pPlainText2Buffer, 0, nPlainText2Len);
303 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
304 CPPUNIT_ASSERT_MESSAGE("wrong decode", aError == rtl_Cipher_E_None);
306 rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
307 t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
308 t_print(T_VERBOSE, " as ascii: %s\n", sPlainText2Str.getStr());
310 // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
312 sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
314 CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
316 delete [] pPlainText2Buffer;
318 delete [] pCipherBuffer;
319 delete [] pPlainTextBuffer;
321 delete [] pArgBuffer;
322 delete [] pKeyBuffer;
324 rtl_cipher_destroy(aCipher);
327 void decode_001()
329 test_encode_and_decode(0,0,"");
330 test_encode_and_decode(0,0,"hallo");
331 test_encode_and_decode(1,0,"B2Aahg5B");
332 test_encode_and_decode(1,2,"Longer text string");
335 void decode_002()
337 test_encode(0,0,"");
338 test_encode(0,0,"hallo");
339 test_encode(1,0,"B2Aahg5B");
340 test_encode(1,2,"Longer text string");
342 // Change the following lines only, if you add, remove or rename
343 // member functions of the current class,
344 // because these macros are need by auto register mechanism.
346 CPPUNIT_TEST_SUITE(decode);
347 CPPUNIT_TEST(decode_001);
348 CPPUNIT_TEST(decode_002);
349 CPPUNIT_TEST_SUITE_END();
350 }; // class decode
351 // -----------------------------------------------------------------------------
352 class decodeBF : public CppUnit::TestFixture
354 public:
355 // initialise your test code values here.
356 void setUp()
360 void tearDown()
364 void decodeBF_001()
367 // Change the following lines only, if you add, remove or rename
368 // member functions of the current class,
369 // because these macros are need by auto register mechanism.
371 CPPUNIT_TEST_SUITE(decodeBF);
372 CPPUNIT_TEST(decodeBF_001);
373 CPPUNIT_TEST_SUITE_END();
374 }; // class decodeBF
375 // -----------------------------------------------------------------------------
376 class destroy : public CppUnit::TestFixture
378 public:
379 // initialise your test code values here.
380 void setUp()
384 void tearDown()
388 void destroy_001()
390 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
391 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
392 rtl_cipher_destroy(aCipher);
394 // Change the following lines only, if you add, remove or rename
395 // member functions of the current class,
396 // because these macros are need by auto register mechanism.
398 CPPUNIT_TEST_SUITE(destroy);
399 CPPUNIT_TEST(destroy_001);
400 CPPUNIT_TEST_SUITE_END();
401 }; // class destroy
402 // -----------------------------------------------------------------------------
403 class destroyBF : public CppUnit::TestFixture
405 public:
406 // initialise your test code values here.
407 void setUp()
411 void tearDown()
415 void destroyBF_001()
417 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
418 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
419 rtl_cipher_destroyBF(aCipher);
420 // more proforma
421 // should not GPF
423 // Change the following lines only, if you add, remove or rename
424 // member functions of the current class,
425 // because these macros are need by auto register mechanism.
427 CPPUNIT_TEST_SUITE(destroyBF);
428 CPPUNIT_TEST(destroyBF_001);
429 CPPUNIT_TEST_SUITE_END();
430 }; // class destroyBF
431 // -----------------------------------------------------------------------------
432 class encode : public CppUnit::TestFixture
434 public:
435 // initialise your test code values here.
436 void setUp()
440 void tearDown()
444 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue)
446 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
447 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
449 sal_uInt32 nKeyLen = 16;
450 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
451 memset(pKeyBuffer, 0, nKeyLen);
452 pKeyBuffer[0] = _nKeyValue;
454 sal_uInt32 nArgLen = 16;
455 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
456 memset(pArgBuffer, 0, nArgLen);
457 pArgBuffer[0] = _nArgValue;
459 t_print(T_VERBOSE, "init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
460 t_print(T_VERBOSE, "init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
462 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
463 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
465 sal_uInt32 nDataLen = 16;
466 sal_uInt8 *pDataBuffer = new sal_uInt8[ nDataLen ];
467 memset(pDataBuffer, 0, nDataLen);
468 pDataBuffer[0] = _nDataValue;
470 sal_uInt32 nLen = 16;
471 sal_uInt8 *pBuffer = new sal_uInt8[ nLen ];
472 memset(pBuffer, 0, nLen);
474 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen);
475 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
477 t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
478 t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
479 t_print(T_VERBOSE, "Data: %s\n", createHex(pDataBuffer, nDataLen).getStr());
480 t_print(T_VERBOSE, " Buf: %s\n", createHex(pBuffer, nLen).getStr());
482 delete [] pBuffer;
483 delete [] pDataBuffer;
485 delete [] pArgBuffer;
486 delete [] pKeyBuffer;
488 rtl_cipher_destroy(aCipher);
491 void encode_001()
493 test_encode(0,0,0);
494 test_encode(1,0,0);
495 test_encode(0,1,0);
496 test_encode(1,1,0);
498 test_encode(0,0,1);
499 test_encode(1,0,1);
500 test_encode(0,1,1);
501 test_encode(1,1,1);
504 // Change the following lines only, if you add, remove or rename
505 // member functions of the current class,
506 // because these macros are need by auto register mechanism.
508 CPPUNIT_TEST_SUITE(encode);
509 CPPUNIT_TEST(encode_001);
510 CPPUNIT_TEST_SUITE_END();
511 }; // class encode
512 // -----------------------------------------------------------------------------
513 class encodeBF : public CppUnit::TestFixture
515 public:
516 // initialise your test code values here.
517 void setUp()
521 void tearDown()
525 void encodeBF_001()
528 // Change the following lines only, if you add, remove or rename
529 // member functions of the current class,
530 // because these macros are need by auto register mechanism.
532 CPPUNIT_TEST_SUITE(encodeBF);
533 CPPUNIT_TEST(encodeBF_001);
534 CPPUNIT_TEST_SUITE_END();
535 }; // class encodeBF
536 // -----------------------------------------------------------------------------
537 class init : public CppUnit::TestFixture
539 public:
540 // initialise your test code values here.
541 void setUp()
545 void tearDown()
549 void init_001()
551 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
552 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
554 sal_uInt32 nKeyLen = 16;
555 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
556 memset(pKeyBuffer, 0, nKeyLen);
558 sal_uInt32 nArgLen = 16;
559 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
560 memset(pArgBuffer, 0, nArgLen);
562 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
563 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
565 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
566 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
568 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
569 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
571 delete [] pArgBuffer;
572 delete [] pKeyBuffer;
574 rtl_cipher_destroy(aCipher);
577 void init_002()
579 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
580 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
582 sal_uInt32 nKeyLen = 16;
583 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
584 memset(pKeyBuffer, 0, nKeyLen);
585 pKeyBuffer[0] = 1;
587 sal_uInt32 nArgLen = 16;
588 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
589 memset(pArgBuffer, 0, nArgLen);
591 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
592 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
594 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
595 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
597 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
598 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
600 delete [] pArgBuffer;
601 delete [] pKeyBuffer;
603 rtl_cipher_destroy(aCipher);
605 void init_003()
607 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
608 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
610 sal_uInt32 nKeyLen = 16;
611 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
612 memset(pKeyBuffer, 0, nKeyLen);
614 sal_uInt32 nArgLen = 16;
615 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
616 memset(pArgBuffer, 0, nArgLen);
617 pArgBuffer[0] = 1;
619 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
620 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
622 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
623 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
625 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
626 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
628 delete [] pArgBuffer;
629 delete [] pKeyBuffer;
631 rtl_cipher_destroy(aCipher);
633 void init_004()
635 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
636 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
638 sal_uInt32 nKeyLen = 16;
639 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
640 memset(pKeyBuffer, 0, nKeyLen);
641 pKeyBuffer[0] = 1;
643 sal_uInt32 nArgLen = 16;
644 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
645 memset(pArgBuffer, 0, nArgLen);
646 pArgBuffer[0] = 1;
648 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
649 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
651 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
652 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
654 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
655 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
657 delete [] pArgBuffer;
658 delete [] pKeyBuffer;
660 rtl_cipher_destroy(aCipher);
662 // Change the following lines only, if you add, remove or rename
663 // member functions of the current class,
664 // because these macros are need by auto register mechanism.
666 CPPUNIT_TEST_SUITE(init);
667 CPPUNIT_TEST(init_001);
668 CPPUNIT_TEST(init_002);
669 CPPUNIT_TEST(init_003);
670 CPPUNIT_TEST(init_004);
671 CPPUNIT_TEST_SUITE_END();
672 }; // class init
673 // -----------------------------------------------------------------------------
674 class initBF : public CppUnit::TestFixture
676 public:
677 // initialise your test code values here.
678 void setUp()
682 void tearDown()
686 void initBF_001()
688 // seems to be the same as init, so empty
691 // Change the following lines only, if you add, remove or rename
692 // member functions of the current class,
693 // because these macros are need by auto register mechanism.
695 CPPUNIT_TEST_SUITE(initBF);
696 CPPUNIT_TEST(initBF_001);
697 CPPUNIT_TEST_SUITE_END();
698 }; // class initBF
700 // -----------------------------------------------------------------------------
702 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::create, "rtl_cipher");
703 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::createBF, "rtl_cipher");
704 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decode, "rtl_cipher");
705 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decodeBF, "rtl_cipher");
706 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroy, "rtl_cipher");
707 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroyBF, "rtl_cipher");
708 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encode, "rtl_cipher");
709 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encodeBF, "rtl_cipher");
710 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::init, "rtl_cipher");
711 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::initBF, "rtl_cipher");
713 } // namespace rtl_cipher
716 // -----------------------------------------------------------------------------
718 // this macro creates an empty function, which will called by the RegisterAllFunctions()
719 // to let the user the possibility to also register some functions by hand.
720 NOADDITIONAL;