1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 29 // MARKER(update_precomp.py): autogen include statement, do not remove 30 #include "precompiled_sal.hxx" 31 32 #include <testshl/simpleheader.hxx> 33 #include <rtl/strbuf.hxx> 34 #include <rtl/cipher.h> 35 36 // ----------------------------------------------------------------------------- 37 namespace rtl_cipher 38 { 39 40 rtl::OString createHex(sal_uInt8 *_pKeyBuffer, sal_uInt32 _nKeyLen) 41 { 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++ ) 45 { 46 sal_Int32 nValue = (sal_Int32)_pKeyBuffer[i]; 47 if (nValue < 16) // maximul hex value for 1 byte 48 { 49 aBuffer.append( sal_Int32(0), 16 /* radix */ ); 50 } 51 aBuffer.append( nValue, 16 /* radix */ ); 52 } 53 54 return aBuffer.makeStringAndClear(); 55 } 56 57 // ----------------------------------------------------------------------------- 58 59 class create : public CppUnit::TestFixture 60 { 61 public: 62 // initialise your test code values here. 63 void setUp() 64 { 65 } 66 67 void tearDown() 68 { 69 } 70 71 void create_001() 72 { 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); 76 } 77 void create_002() 78 { 79 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB); 80 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); 81 } 82 void create_003() 83 { 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); 87 } 88 void create_004() 89 { 90 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC); 91 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); 92 } 93 void create_005() 94 { 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); 98 } 99 void create_006() 100 { 101 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream); 102 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); 103 } 104 void create_007() 105 { 106 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid); 107 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); 108 } 109 void create_008() 110 { 111 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid); 112 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); 113 } 114 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. 118 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 130 131 // ----------------------------------------------------------------------------- 132 class createBF : public CppUnit::TestFixture 133 { 134 public: 135 // initialise your test code values here. 136 void setUp() 137 { 138 } 139 140 void tearDown() 141 { 142 } 143 144 void createBF_001() 145 { 146 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB); 147 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 148 rtl_cipher_destroy(aCipher); 149 } 150 void createBF_002() 151 { 152 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC); 153 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 154 rtl_cipher_destroy(aCipher); 155 } 156 void createBF_003() 157 { 158 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream); 159 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 160 rtl_cipher_destroy(aCipher); 161 } 162 void createBF_004() 163 { 164 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid); 165 CPPUNIT_ASSERT_MESSAGE("create provide wrong object.", aCipher == NULL); 166 // rtl_cipher_destroy(aCipher); 167 } 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. 171 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 181 { 182 public: 183 // initialise your test code values here. 184 void setUp() 185 { 186 } 187 188 void tearDown() 189 { 190 } 191 192 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr) 193 { 194 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 195 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 196 197 sal_uInt32 nKeyLen = 16; 198 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 199 memset(pKeyBuffer, 0, nKeyLen); 200 pKeyBuffer[0] = _nKeyValue; 201 202 sal_uInt32 nArgLen = 16; 203 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 204 memset(pArgBuffer, 0, nArgLen); 205 pArgBuffer[0] = _nArgValue; 206 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()); 209 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); 212 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); 217 218 sal_uInt32 nCipherLen = 16; 219 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ]; 220 memset(pCipherBuffer, 0, nCipherLen); 221 222 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen); 223 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None); 224 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()); 229 230 sal_uInt32 nPlainText2Len = 16; 231 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ]; 232 memset(pPlainText2Buffer, 0, nPlainText2Len); 233 234 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len); 235 CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None); 236 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()); 240 // 241 // // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr()); 242 // 243 // sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16); 244 // 245 // CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0); 246 // 247 // delete [] pPlainText2Buffer; 248 // 249 // delete [] pCipherBuffer; 250 // delete [] pPlainTextBuffer; 251 // 252 // delete [] pArgBuffer; 253 // delete [] pKeyBuffer; 254 // 255 // rtl_cipher_destroy(aCipher); 256 } 257 258 void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, rtl::OString const& _sPlainTextStr) 259 { 260 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 261 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 262 263 sal_uInt32 nKeyLen = 16; 264 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 265 memset(pKeyBuffer, 0, nKeyLen); 266 pKeyBuffer[0] = _nKeyValue; 267 268 sal_uInt32 nArgLen = 16; 269 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 270 memset(pArgBuffer, 0, nArgLen); 271 pArgBuffer[0] = _nArgValue; 272 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()); 275 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); 278 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); 283 284 sal_uInt32 nCipherLen = 16; 285 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ]; 286 memset(pCipherBuffer, 0, nCipherLen); 287 288 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen); 289 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None); 290 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()); 295 296 sal_uInt32 nPlainText2Len = 16; 297 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ]; 298 memset(pPlainText2Buffer, 0, nPlainText2Len); 299 300 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len); 301 CPPUNIT_ASSERT_MESSAGE("wrong decode", aError == rtl_Cipher_E_None); 302 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()); 306 307 // t_print(" Buf: %s\n", createHex(pCipherBuffer, nCipherLen).getStr()); 308 309 sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16); 310 311 CPPUNIT_ASSERT_MESSAGE("compare between plain and decoded plain failed", nCompare == 0); 312 313 delete [] pPlainText2Buffer; 314 315 delete [] pCipherBuffer; 316 delete [] pPlainTextBuffer; 317 318 delete [] pArgBuffer; 319 delete [] pKeyBuffer; 320 321 rtl_cipher_destroy(aCipher); 322 } 323 324 void decode_001() 325 { 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"); 330 } 331 332 void decode_002() 333 { 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"); 338 } 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. 342 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 350 { 351 public: 352 // initialise your test code values here. 353 void setUp() 354 { 355 } 356 357 void tearDown() 358 { 359 } 360 361 void decodeBF_001() 362 { 363 } 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. 367 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 374 { 375 public: 376 // initialise your test code values here. 377 void setUp() 378 { 379 } 380 381 void tearDown() 382 { 383 } 384 385 void destroy_001() 386 { 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); 390 } 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. 394 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 401 { 402 public: 403 // initialise your test code values here. 404 void setUp() 405 { 406 } 407 408 void tearDown() 409 { 410 } 411 412 void destroyBF_001() 413 { 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 419 } 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. 423 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 430 { 431 public: 432 // initialise your test code values here. 433 void setUp() 434 { 435 } 436 437 void tearDown() 438 { 439 } 440 441 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue) 442 { 443 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 444 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 445 446 sal_uInt32 nKeyLen = 16; 447 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 448 memset(pKeyBuffer, 0, nKeyLen); 449 pKeyBuffer[0] = _nKeyValue; 450 451 sal_uInt32 nArgLen = 16; 452 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 453 memset(pArgBuffer, 0, nArgLen); 454 pArgBuffer[0] = _nArgValue; 455 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()); 458 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); 461 462 sal_uInt32 nDataLen = 16; 463 sal_uInt8 *pDataBuffer = new sal_uInt8[ nDataLen ]; 464 memset(pDataBuffer, 0, nDataLen); 465 pDataBuffer[0] = _nDataValue; 466 467 sal_uInt32 nLen = 16; 468 sal_uInt8 *pBuffer = new sal_uInt8[ nLen ]; 469 memset(pBuffer, 0, nLen); 470 471 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen); 472 CPPUNIT_ASSERT_MESSAGE("wrong encode", aError == rtl_Cipher_E_None); 473 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()); 478 479 delete [] pBuffer; 480 delete [] pDataBuffer; 481 482 delete [] pArgBuffer; 483 delete [] pKeyBuffer; 484 485 rtl_cipher_destroy(aCipher); 486 } 487 488 void encode_001() 489 { 490 test_encode(0,0,0); 491 test_encode(1,0,0); 492 test_encode(0,1,0); 493 test_encode(1,1,0); 494 495 test_encode(0,0,1); 496 test_encode(1,0,1); 497 test_encode(0,1,1); 498 test_encode(1,1,1); 499 } 500 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. 504 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 511 { 512 public: 513 // initialise your test code values here. 514 void setUp() 515 { 516 } 517 518 void tearDown() 519 { 520 } 521 522 void encodeBF_001() 523 { 524 } 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. 528 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 535 { 536 public: 537 // initialise your test code values here. 538 void setUp() 539 { 540 } 541 542 void tearDown() 543 { 544 } 545 546 void init_001() 547 { 548 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 549 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 550 551 sal_uInt32 nKeyLen = 16; 552 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 553 memset(pKeyBuffer, 0, nKeyLen); 554 555 sal_uInt32 nArgLen = 16; 556 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 557 memset(pArgBuffer, 0, nArgLen); 558 559 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 560 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 561 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); 564 565 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 566 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 567 568 delete [] pArgBuffer; 569 delete [] pKeyBuffer; 570 571 rtl_cipher_destroy(aCipher); 572 } 573 574 void init_002() 575 { 576 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 577 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 578 579 sal_uInt32 nKeyLen = 16; 580 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 581 memset(pKeyBuffer, 0, nKeyLen); 582 pKeyBuffer[0] = 1; 583 584 sal_uInt32 nArgLen = 16; 585 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 586 memset(pArgBuffer, 0, nArgLen); 587 588 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 589 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 590 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); 593 594 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 595 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 596 597 delete [] pArgBuffer; 598 delete [] pKeyBuffer; 599 600 rtl_cipher_destroy(aCipher); 601 } 602 void init_003() 603 { 604 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 605 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 606 607 sal_uInt32 nKeyLen = 16; 608 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 609 memset(pKeyBuffer, 0, nKeyLen); 610 611 sal_uInt32 nArgLen = 16; 612 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 613 memset(pArgBuffer, 0, nArgLen); 614 pArgBuffer[0] = 1; 615 616 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 617 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 618 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); 621 622 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 623 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 624 625 delete [] pArgBuffer; 626 delete [] pKeyBuffer; 627 628 rtl_cipher_destroy(aCipher); 629 } 630 void init_004() 631 { 632 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB); 633 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != NULL); 634 635 sal_uInt32 nKeyLen = 16; 636 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 637 memset(pKeyBuffer, 0, nKeyLen); 638 pKeyBuffer[0] = 1; 639 640 sal_uInt32 nArgLen = 16; 641 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ]; 642 memset(pArgBuffer, 0, nArgLen); 643 pArgBuffer[0] = 1; 644 645 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 646 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 647 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); 650 651 t_print(T_VERBOSE, "Key: %s\n", createHex(pKeyBuffer, nKeyLen).getStr()); 652 t_print(T_VERBOSE, "Arg: %s\n", createHex(pArgBuffer, nArgLen).getStr()); 653 654 delete [] pArgBuffer; 655 delete [] pKeyBuffer; 656 657 rtl_cipher_destroy(aCipher); 658 } 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. 662 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 672 { 673 public: 674 // initialise your test code values here. 675 void setUp() 676 { 677 } 678 679 void tearDown() 680 { 681 } 682 683 void initBF_001() 684 { 685 // seems to be the same as init, so empty 686 } 687 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. 691 692 CPPUNIT_TEST_SUITE(initBF); 693 CPPUNIT_TEST(initBF_001); 694 CPPUNIT_TEST_SUITE_END(); 695 }; // class initBF 696 697 // ----------------------------------------------------------------------------- 698 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"); 709 710 } // namespace rtl_cipher 711 712 713 // ----------------------------------------------------------------------------- 714 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; 718