merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / qa / rtl / cipher / rtl_cipher.cxx
blob127ceef5a27ec36abfa84153f4defacaa50b21ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
32 #include <testshl/simpleheader.hxx>
33 #include <rtl/strbuf.hxx>
34 #include <rtl/cipher.h>
36 // -----------------------------------------------------------------------------
37 namespace rtl_cipher
40 rtl::OString createHex(sal_uInt8 *_pKeyBuffer, sal_uInt32 _nKeyLen)
42 // Create hex-value string from the value to keep the string size minimal
43 rtl::OStringBuffer aBuffer( _nKeyLen * 2 + 1 );
44 for ( sal_uInt32 i = 0; i < _nKeyLen; i++ )
46 sal_Int32 nValue = (sal_Int32)_pKeyBuffer[i];
47 if (nValue < 16) // maximul hex value for 1 byte
49 aBuffer.append( sal_Int32(0), 16 /* radix */ );
51 aBuffer.append( nValue, 16 /* radix */ );
54 return aBuffer.makeStringAndClear();
57 // -----------------------------------------------------------------------------
59 class create : public CppUnit::TestFixture
61 public:
62 // initialise your test code values here.
63 void setUp()
67 void tearDown()
71 void create_001()
73 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
74 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
75 rtl_cipher_destroy(aCipher);
77 void create_002()
79 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB);
80 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
82 void create_003()
84 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
85 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
86 rtl_cipher_destroy(aCipher);
88 void create_004()
90 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC);
91 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
93 void create_005()
95 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
96 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
97 rtl_cipher_destroy(aCipher);
99 void create_006()
101 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream);
102 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
104 void create_007()
106 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid);
107 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
109 void create_008()
111 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid);
112 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
115 // Change the following lines only, if you add, remove or rename
116 // member functions of the current class,
117 // because these macros are need by auto register mechanism.
119 CPPUNIT_TEST_SUITE(create);
120 CPPUNIT_TEST(create_001);
121 CPPUNIT_TEST(create_002);
122 CPPUNIT_TEST(create_003);
123 CPPUNIT_TEST(create_004);
124 CPPUNIT_TEST(create_005);
125 CPPUNIT_TEST(create_006);
126 CPPUNIT_TEST(create_007);
127 CPPUNIT_TEST(create_008);
128 CPPUNIT_TEST_SUITE_END();
129 }; // class create
131 // -----------------------------------------------------------------------------
132 class createBF : public CppUnit::TestFixture
134 public:
135 // initialise your test code values here.
136 void setUp()
140 void tearDown()
144 void createBF_001()
146 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
147 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
148 rtl_cipher_destroy(aCipher);
150 void createBF_002()
152 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC);
153 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
154 rtl_cipher_destroy(aCipher);
156 void createBF_003()
158 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream);
159 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
160 rtl_cipher_destroy(aCipher);
162 void createBF_004()
164 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid);
165 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL);
166 // rtl_cipher_destroy(aCipher);
168 // Change the following lines only, if you add, remove or rename
169 // member functions of the current class,
170 // because these macros are need by auto register mechanism.
172 CPPUNIT_TEST_SUITE(createBF);
173 CPPUNIT_TEST(createBF_001);
174 CPPUNIT_TEST(createBF_002);
175 CPPUNIT_TEST(createBF_003);
176 CPPUNIT_TEST(createBF_004);
177 CPPUNIT_TEST_SUITE_END();
178 }; // class createBF
179 // -----------------------------------------------------------------------------
180 class decode : public CppUnit::TestFixture
182 public:
183 // initialise your test code values here.
184 void setUp()
188 void tearDown()
192 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
194 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
195 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
197 sal_uInt32 nKeyLen = 16;
198 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
199 memset(pKeyBuffer, 0, nKeyLen);
200 pKeyBuffer[0] = _nKeyValue;
202 sal_uInt32 nArgLen = 16;
203 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
204 memset(pArgBuffer, 0, nArgLen);
205 pArgBuffer[0] = _nArgValue;
207 t_print(T_VERBOSE, " init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
208 t_print(T_VERBOSE, " init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
210 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
211 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
213 sal_uInt32 nPlainTextLen = 16;
214 sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
215 memset(pPlainTextBuffer, 0, nPlainTextLen);
216 strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
218 sal_uInt32 nCipherLen = 16;
219 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ];
220 memset(pCipherBuffer, 0, nCipherLen);
222 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
223 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
225 t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
226 t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
227 t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
228 t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
230 sal_uInt32 nPlainText2Len = 16;
231 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
232 memset(pPlainText2Buffer, 0, nPlainText2Len);
234 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
235 CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None);
237 // rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
238 // t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
239 // t_print(T_VERBOSE, " ascii: %s\n", sPlainText2Str.getStr());
241 // // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
243 // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
245 // CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
247 // delete [] pPlainText2Buffer;
249 // delete [] pCipherBuffer;
250 // delete [] pPlainTextBuffer;
252 // delete [] pArgBuffer;
253 // delete [] pKeyBuffer;
255 // rtl_cipher_destroy(aCipher);
258 void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr)
260 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
261 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
263 sal_uInt32 nKeyLen = 16;
264 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
265 memset(pKeyBuffer, 0, nKeyLen);
266 pKeyBuffer[0] = _nKeyValue;
268 sal_uInt32 nArgLen = 16;
269 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
270 memset(pArgBuffer, 0, nArgLen);
271 pArgBuffer[0] = _nArgValue;
273 t_print(T_VERBOSE, " init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
274 t_print(T_VERBOSE, " init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
276 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
277 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
279 sal_uInt32 nPlainTextLen = 16;
280 sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
281 memset(pPlainTextBuffer, 0, nPlainTextLen);
282 strncpy((char*)pPlainTextBuffer, _sPlainTextStr.getStr(), 16);
284 sal_uInt32 nCipherLen = 16;
285 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ];
286 memset(pCipherBuffer, 0, nCipherLen);
288 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
289 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
291 t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
292 t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
293 t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainTextBuffer, nPlainTextLen).getStr());
294 t_print( "Cipher Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
296 sal_uInt32 nPlainText2Len = 16;
297 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
298 memset(pPlainText2Buffer, 0, nPlainText2Len);
300 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
301 CPPUNIT_ASSERT_MESSAGE("wrong decode", aError == rtl_Cipher_E_None);
303 rtl::OString sPlainText2Str((char*)pPlainText2Buffer, nPlainText2Len);
304 t_print(T_VERBOSE, " Plain: %s\n", createHex(pPlainText2Buffer, nPlainText2Len).getStr());
305 t_print(T_VERBOSE, " as ascii: %s\n", sPlainText2Str.getStr());
307 // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr());
309 sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
311 CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0);
313 delete [] pPlainText2Buffer;
315 delete [] pCipherBuffer;
316 delete [] pPlainTextBuffer;
318 delete [] pArgBuffer;
319 delete [] pKeyBuffer;
321 rtl_cipher_destroy(aCipher);
324 void decode_001()
326 test_encode_and_decode(0,0,"");
327 test_encode_and_decode(0,0,"hallo");
328 test_encode_and_decode(1,0,"B2Aahg5B");
329 test_encode_and_decode(1,2,"Longer text string");
332 void decode_002()
334 test_encode(0,0,"");
335 test_encode(0,0,"hallo");
336 test_encode(1,0,"B2Aahg5B");
337 test_encode(1,2,"Longer text string");
339 // Change the following lines only, if you add, remove or rename
340 // member functions of the current class,
341 // because these macros are need by auto register mechanism.
343 CPPUNIT_TEST_SUITE(decode);
344 CPPUNIT_TEST(decode_001);
345 CPPUNIT_TEST(decode_002);
346 CPPUNIT_TEST_SUITE_END();
347 }; // class decode
348 // -----------------------------------------------------------------------------
349 class decodeBF : public CppUnit::TestFixture
351 public:
352 // initialise your test code values here.
353 void setUp()
357 void tearDown()
361 void decodeBF_001()
364 // Change the following lines only, if you add, remove or rename
365 // member functions of the current class,
366 // because these macros are need by auto register mechanism.
368 CPPUNIT_TEST_SUITE(decodeBF);
369 CPPUNIT_TEST(decodeBF_001);
370 CPPUNIT_TEST_SUITE_END();
371 }; // class decodeBF
372 // -----------------------------------------------------------------------------
373 class destroy : public CppUnit::TestFixture
375 public:
376 // initialise your test code values here.
377 void setUp()
381 void tearDown()
385 void destroy_001()
387 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
388 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
389 rtl_cipher_destroy(aCipher);
391 // Change the following lines only, if you add, remove or rename
392 // member functions of the current class,
393 // because these macros are need by auto register mechanism.
395 CPPUNIT_TEST_SUITE(destroy);
396 CPPUNIT_TEST(destroy_001);
397 CPPUNIT_TEST_SUITE_END();
398 }; // class destroy
399 // -----------------------------------------------------------------------------
400 class destroyBF : public CppUnit::TestFixture
402 public:
403 // initialise your test code values here.
404 void setUp()
408 void tearDown()
412 void destroyBF_001()
414 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
415 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
416 rtl_cipher_destroyBF(aCipher);
417 // more proforma
418 // should not GPF
420 // Change the following lines only, if you add, remove or rename
421 // member functions of the current class,
422 // because these macros are need by auto register mechanism.
424 CPPUNIT_TEST_SUITE(destroyBF);
425 CPPUNIT_TEST(destroyBF_001);
426 CPPUNIT_TEST_SUITE_END();
427 }; // class destroyBF
428 // -----------------------------------------------------------------------------
429 class encode : public CppUnit::TestFixture
431 public:
432 // initialise your test code values here.
433 void setUp()
437 void tearDown()
441 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue)
443 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
444 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
446 sal_uInt32 nKeyLen = 16;
447 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
448 memset(pKeyBuffer, 0, nKeyLen);
449 pKeyBuffer[0] = _nKeyValue;
451 sal_uInt32 nArgLen = 16;
452 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
453 memset(pArgBuffer, 0, nArgLen);
454 pArgBuffer[0] = _nArgValue;
456 t_print(T_VERBOSE, "init Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
457 t_print(T_VERBOSE, "init Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
459 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
460 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
462 sal_uInt32 nDataLen = 16;
463 sal_uInt8 *pDataBuffer = new sal_uInt8[ nDataLen ];
464 memset(pDataBuffer, 0, nDataLen);
465 pDataBuffer[0] = _nDataValue;
467 sal_uInt32 nLen = 16;
468 sal_uInt8 *pBuffer = new sal_uInt8[ nLen ];
469 memset(pBuffer, 0, nLen);
471 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen);
472 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None);
474 t_print(T_VERBOSE, " Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
475 t_print(T_VERBOSE, " Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
476 t_print(T_VERBOSE, "Data: %s\n", createHex(pDataBuffer, nDataLen).getStr());
477 t_print(T_VERBOSE, " Buf: %s\n", createHex(pBuffer, nLen).getStr());
479 delete [] pBuffer;
480 delete [] pDataBuffer;
482 delete [] pArgBuffer;
483 delete [] pKeyBuffer;
485 rtl_cipher_destroy(aCipher);
488 void encode_001()
490 test_encode(0,0,0);
491 test_encode(1,0,0);
492 test_encode(0,1,0);
493 test_encode(1,1,0);
495 test_encode(0,0,1);
496 test_encode(1,0,1);
497 test_encode(0,1,1);
498 test_encode(1,1,1);
501 // Change the following lines only, if you add, remove or rename
502 // member functions of the current class,
503 // because these macros are need by auto register mechanism.
505 CPPUNIT_TEST_SUITE(encode);
506 CPPUNIT_TEST(encode_001);
507 CPPUNIT_TEST_SUITE_END();
508 }; // class encode
509 // -----------------------------------------------------------------------------
510 class encodeBF : public CppUnit::TestFixture
512 public:
513 // initialise your test code values here.
514 void setUp()
518 void tearDown()
522 void encodeBF_001()
525 // Change the following lines only, if you add, remove or rename
526 // member functions of the current class,
527 // because these macros are need by auto register mechanism.
529 CPPUNIT_TEST_SUITE(encodeBF);
530 CPPUNIT_TEST(encodeBF_001);
531 CPPUNIT_TEST_SUITE_END();
532 }; // class encodeBF
533 // -----------------------------------------------------------------------------
534 class init : public CppUnit::TestFixture
536 public:
537 // initialise your test code values here.
538 void setUp()
542 void tearDown()
546 void init_001()
548 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
549 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
551 sal_uInt32 nKeyLen = 16;
552 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
553 memset(pKeyBuffer, 0, nKeyLen);
555 sal_uInt32 nArgLen = 16;
556 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
557 memset(pArgBuffer, 0, nArgLen);
559 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
560 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
562 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
563 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
565 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
566 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
568 delete [] pArgBuffer;
569 delete [] pKeyBuffer;
571 rtl_cipher_destroy(aCipher);
574 void init_002()
576 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
577 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
579 sal_uInt32 nKeyLen = 16;
580 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
581 memset(pKeyBuffer, 0, nKeyLen);
582 pKeyBuffer[0] = 1;
584 sal_uInt32 nArgLen = 16;
585 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
586 memset(pArgBuffer, 0, nArgLen);
588 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
589 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
591 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
592 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
594 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
595 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
597 delete [] pArgBuffer;
598 delete [] pKeyBuffer;
600 rtl_cipher_destroy(aCipher);
602 void init_003()
604 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
605 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
607 sal_uInt32 nKeyLen = 16;
608 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
609 memset(pKeyBuffer, 0, nKeyLen);
611 sal_uInt32 nArgLen = 16;
612 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
613 memset(pArgBuffer, 0, nArgLen);
614 pArgBuffer[0] = 1;
616 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
617 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
619 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
620 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
622 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
623 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
625 delete [] pArgBuffer;
626 delete [] pKeyBuffer;
628 rtl_cipher_destroy(aCipher);
630 void init_004()
632 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
633 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL);
635 sal_uInt32 nKeyLen = 16;
636 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
637 memset(pKeyBuffer, 0, nKeyLen);
638 pKeyBuffer[0] = 1;
640 sal_uInt32 nArgLen = 16;
641 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
642 memset(pArgBuffer, 0, nArgLen);
643 pArgBuffer[0] = 1;
645 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
646 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
648 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
649 CPPUNIT_ASSERT_MESSAGE("wrong init", aError == rtl_Cipher_E_None);
651 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr());
652 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr());
654 delete [] pArgBuffer;
655 delete [] pKeyBuffer;
657 rtl_cipher_destroy(aCipher);
659 // Change the following lines only, if you add, remove or rename
660 // member functions of the current class,
661 // because these macros are need by auto register mechanism.
663 CPPUNIT_TEST_SUITE(init);
664 CPPUNIT_TEST(init_001);
665 CPPUNIT_TEST(init_002);
666 CPPUNIT_TEST(init_003);
667 CPPUNIT_TEST(init_004);
668 CPPUNIT_TEST_SUITE_END();
669 }; // class init
670 // -----------------------------------------------------------------------------
671 class initBF : public CppUnit::TestFixture
673 public:
674 // initialise your test code values here.
675 void setUp()
679 void tearDown()
683 void initBF_001()
685 // seems to be the same as init, so empty
688 // Change the following lines only, if you add, remove or rename
689 // member functions of the current class,
690 // because these macros are need by auto register mechanism.
692 CPPUNIT_TEST_SUITE(initBF);
693 CPPUNIT_TEST(initBF_001);
694 CPPUNIT_TEST_SUITE_END();
695 }; // class initBF
697 // -----------------------------------------------------------------------------
699 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::create, "rtl_cipher");
700 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::createBF, "rtl_cipher");
701 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decode, "rtl_cipher");
702 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::decodeBF, "rtl_cipher");
703 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroy, "rtl_cipher");
704 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::destroyBF, "rtl_cipher");
705 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encode, "rtl_cipher");
706 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::encodeBF, "rtl_cipher");
707 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::init, "rtl_cipher");
708 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_cipher::initBF, "rtl_cipher");
710 } // namespace rtl_cipher
713 // -----------------------------------------------------------------------------
715 // this macro creates an empty function, which will called by the RegisterAllFunctions()
716 // to let the user the possibility to also register some functions by hand.
717 NOADDITIONAL;