Debian Codegraph @

sal/qa/rtl/cipher/rtl_cipher.cxx

raw
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 #include <cstring>
21
22 #include <sal/types.h>
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
25
26 #include <rtl/cipher.h>
27 #include <rtl/string.hxx>
28
29 namespace rtl_cipher
30 {
31
32 class create : public CppUnit::TestFixture
33 {
34 public:
35
36 void create_001()
37 {
38 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
39 #if defined LIBO_CIPHER_OPENSSL_BACKEND
40 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
41 #else
42 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
43 rtl_cipher_destroy(aCipher);
44 #endif
45 }
46 void create_002()
47 {
48 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeECB);
49 CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher);
50 }
51 void create_003()
52 {
53 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
54 #if defined LIBO_CIPHER_OPENSSL_BACKEND
55 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
56 #else
57 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
58 rtl_cipher_destroy(aCipher);
59 #endif
60 }
61 void create_004()
62 {
63 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeCBC);
64 CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher);
65 }
66 void create_005()
67 {
68 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream);
69 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
70 rtl_cipher_destroy(aCipher);
71 }
72 void create_006()
73 {
74 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeStream);
75 CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher);
76 }
77 void create_007()
78 {
79 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeInvalid);
80 CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher);
81 }
82 void create_008()
83 {
84 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmInvalid, rtl_Cipher_ModeInvalid);
85 CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher);
86 }
87
88 // Change the following lines only, if you add, remove or rename
89 // member functions of the current class,
90 // because these macros are need by auto register mechanism.
91
92 CPPUNIT_TEST_SUITE(create);
93 CPPUNIT_TEST(create_001);
94 CPPUNIT_TEST(create_002);
95 CPPUNIT_TEST(create_003);
96 CPPUNIT_TEST(create_004);
97 CPPUNIT_TEST(create_005);
98 CPPUNIT_TEST(create_006);
99 CPPUNIT_TEST(create_007);
100 CPPUNIT_TEST(create_008);
101 CPPUNIT_TEST_SUITE_END();
102 }; // class create
103
104 class createBF : public CppUnit::TestFixture
105 {
106 public:
107
108 void createBF_001()
109 {
110 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
111 #if defined LIBO_CIPHER_OPENSSL_BACKEND
112 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
113 #else
114 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
115 rtl_cipher_destroy(aCipher);
116 #endif
117 }
118 void createBF_002()
119 {
120 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeCBC);
121 #if defined LIBO_CIPHER_OPENSSL_BACKEND
122 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
123 #else
124 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
125 rtl_cipher_destroy(aCipher);
126 #endif
127 }
128 void createBF_003()
129 {
130 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeStream);
131 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
132 rtl_cipher_destroy(aCipher);
133 }
134 void createBF_004()
135 {
136 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeInvalid);
137 CPPUNIT_ASSERT_EQUAL_MESSAGE("create provide wrong object.", static_cast<rtlCipher>(nullptr), aCipher);
138 // rtl_cipher_destroy(aCipher);
139 }
140 // Change the following lines only, if you add, remove or rename
141 // member functions of the current class,
142 // because these macros are need by auto register mechanism.
143
144 CPPUNIT_TEST_SUITE(createBF);
145 CPPUNIT_TEST(createBF_001);
146 CPPUNIT_TEST(createBF_002);
147 CPPUNIT_TEST(createBF_003);
148 CPPUNIT_TEST(createBF_004);
149 CPPUNIT_TEST_SUITE_END();
150 }; // class createBF
151
152 class decode : public CppUnit::TestFixture
153 {
154 public:
155
156 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, OString const& _sPlainTextStr)
157 {
158 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
159 #if defined LIBO_CIPHER_OPENSSL_BACKEND
160 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
161 (void) _nKeyValue;
162 (void) _nArgValue;
163 (void) _sPlainTextStr;
164 #else
165 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
166
167 sal_uInt32 nKeyLen = 16;
168 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
169 memset(pKeyBuffer, 0, nKeyLen);
170 pKeyBuffer[0] = _nKeyValue;
171
172 sal_uInt32 nArgLen = 16;
173 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
174 memset(pArgBuffer, 0, nArgLen);
175 pArgBuffer[0] = _nArgValue;
176
177 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
178 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
179
180 sal_uInt32 nPlainTextLen = 16;
181 sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
182 memset(pPlainTextBuffer, 0, nPlainTextLen);
183 strncpy(reinterpret_cast<char*>(pPlainTextBuffer), _sPlainTextStr.getStr(), 16);
184
185 sal_uInt32 nCipherLen = 16;
186 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ];
187 memset(pCipherBuffer, 0, nCipherLen);
188
189 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
190 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong encode", rtl_Cipher_E_None, aError);
191
192 sal_uInt32 nPlainText2Len = 16;
193 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
194 memset(pPlainText2Buffer, 0, nPlainText2Len);
195
196 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
197 CPPUNIT_ASSERT_MESSAGE("decode should not work", aError != rtl_Cipher_E_None);
198
199 delete [] pPlainText2Buffer;
200
201 delete [] pCipherBuffer;
202 delete [] pPlainTextBuffer;
203
204 delete [] pArgBuffer;
205 delete [] pKeyBuffer;
206
207 rtl_cipher_destroy(aCipher);
208 #endif
209 }
210
211 void test_encode_and_decode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, OString const& _sPlainTextStr)
212 {
213 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
214 #if defined LIBO_CIPHER_OPENSSL_BACKEND
215 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
216 (void) _nKeyValue;
217 (void) _nArgValue;
218 (void) _sPlainTextStr;
219 #else
220 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
221
222 sal_uInt32 nKeyLen = 16;
223 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
224 memset(pKeyBuffer, 0, nKeyLen);
225 pKeyBuffer[0] = _nKeyValue;
226
227 sal_uInt32 nArgLen = 16;
228 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
229 memset(pArgBuffer, 0, nArgLen);
230 pArgBuffer[0] = _nArgValue;
231
232 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionBoth, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
233 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
234
235 sal_uInt32 nPlainTextLen = 16;
236 sal_uInt8 *pPlainTextBuffer = new sal_uInt8[ nPlainTextLen ];
237 memset(pPlainTextBuffer, 0, nPlainTextLen);
238 strncpy(reinterpret_cast<char*>(pPlainTextBuffer), _sPlainTextStr.getStr(), 16);
239
240 sal_uInt32 nCipherLen = 16;
241 sal_uInt8 *pCipherBuffer = new sal_uInt8[ nCipherLen ];
242 memset(pCipherBuffer, 0, nCipherLen);
243
244 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pPlainTextBuffer, nPlainTextLen, pCipherBuffer, nCipherLen);
245 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong encode", rtl_Cipher_E_None, aError);
246
247 sal_uInt32 nPlainText2Len = 16;
248 sal_uInt8 *pPlainText2Buffer = new sal_uInt8[ nPlainText2Len ];
249 memset(pPlainText2Buffer, 0, nPlainText2Len);
250
251 /* rtlCipherError */ aError = rtl_cipher_decode(aCipher, pCipherBuffer, nCipherLen, pPlainText2Buffer, nPlainText2Len);
252 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong decode", rtl_Cipher_E_None, aError);
253
254 sal_Int32 nCompare = memcmp(pPlainTextBuffer, pPlainText2Buffer, 16);
255
256 CPPUNIT_ASSERT_EQUAL_MESSAGE("compare between plain and decoded plain failed", static_cast<sal_Int32>(0), nCompare);
257
258 delete [] pPlainText2Buffer;
259
260 delete [] pCipherBuffer;
261 delete [] pPlainTextBuffer;
262
263 delete [] pArgBuffer;
264 delete [] pKeyBuffer;
265
266 rtl_cipher_destroy(aCipher);
267 #endif
268 }
269
270 void decode_001()
271 {
272 test_encode_and_decode(0,0,""_ostr);
273 test_encode_and_decode(0,0,"hallo"_ostr);
274 test_encode_and_decode(1,0,"B2Aahg5B"_ostr);
275 test_encode_and_decode(1,2,"Longer text string"_ostr);
276 }
277
278 void decode_002()
279 {
280 test_encode(0,0,""_ostr);
281 test_encode(0,0,"hallo"_ostr);
282 test_encode(1,0,"B2Aahg5B"_ostr);
283 test_encode(1,2,"Longer text string"_ostr);
284 }
285 // Change the following lines only, if you add, remove or rename
286 // member functions of the current class,
287 // because these macros are need by auto register mechanism.
288
289 CPPUNIT_TEST_SUITE(decode);
290 CPPUNIT_TEST(decode_001);
291 CPPUNIT_TEST(decode_002);
292 CPPUNIT_TEST_SUITE_END();
293 }; // class decode
294
295 class decodeBF : public CppUnit::TestFixture
296 {
297 public:
298
299 void decodeBF_001()
300 {
301 }
302 // Change the following lines only, if you add, remove or rename
303 // member functions of the current class,
304 // because these macros are need by auto register mechanism.
305
306 CPPUNIT_TEST_SUITE(decodeBF);
307 CPPUNIT_TEST(decodeBF_001);
308 CPPUNIT_TEST_SUITE_END();
309 }; // class decodeBF
310
311 class destroy : public CppUnit::TestFixture
312 {
313 public:
314
315 void destroy_001()
316 {
317 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeCBC);
318 #if defined LIBO_CIPHER_OPENSSL_BACKEND
319 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
320 #else
321 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
322 rtl_cipher_destroy(aCipher);
323 #endif
324 }
325 // Change the following lines only, if you add, remove or rename
326 // member functions of the current class,
327 // because these macros are need by auto register mechanism.
328
329 CPPUNIT_TEST_SUITE(destroy);
330 CPPUNIT_TEST(destroy_001);
331 CPPUNIT_TEST_SUITE_END();
332 }; // class destroy
333
334 class destroyBF : public CppUnit::TestFixture
335 {
336 public:
337
338 void destroyBF_001()
339 {
340 rtlCipher aCipher = rtl_cipher_createBF(rtl_Cipher_ModeECB);
341 #if defined LIBO_CIPHER_OPENSSL_BACKEND
342 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
343 #else
344 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
345 rtl_cipher_destroyBF(aCipher);
346 // more proforma
347 // should not GPF
348 #endif
349 }
350 // Change the following lines only, if you add, remove or rename
351 // member functions of the current class,
352 // because these macros are need by auto register mechanism.
353
354 CPPUNIT_TEST_SUITE(destroyBF);
355 CPPUNIT_TEST(destroyBF_001);
356 CPPUNIT_TEST_SUITE_END();
357 }; // class destroyBF
358
359 class encode : public CppUnit::TestFixture
360 {
361 public:
362
363 void test_encode(sal_uInt8 _nKeyValue, sal_uInt8 _nArgValue, sal_uInt8 _nDataValue)
364 {
365 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
366 #if defined LIBO_CIPHER_OPENSSL_BACKEND
367 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
368 (void) _nKeyValue;
369 (void) _nArgValue;
370 (void) _nDataValue;
371 #else
372 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
373
374 sal_uInt32 nKeyLen = 16;
375 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
376 memset(pKeyBuffer, 0, nKeyLen);
377 pKeyBuffer[0] = _nKeyValue;
378
379 sal_uInt32 nArgLen = 16;
380 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
381 memset(pArgBuffer, 0, nArgLen);
382 pArgBuffer[0] = _nArgValue;
383
384 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
385 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
386
387 sal_uInt32 nDataLen = 16;
388 sal_uInt8 *pDataBuffer = new sal_uInt8[ nDataLen ];
389 memset(pDataBuffer, 0, nDataLen);
390 pDataBuffer[0] = _nDataValue;
391
392 sal_uInt32 nLen = 16;
393 sal_uInt8 *pBuffer = new sal_uInt8[ nLen ];
394 memset(pBuffer, 0, nLen);
395
396 /* rtlCipherError */ aError = rtl_cipher_encode(aCipher, pDataBuffer, nDataLen, pBuffer, nLen);
397 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong encode", rtl_Cipher_E_None, aError);
398
399 delete [] pBuffer;
400 delete [] pDataBuffer;
401
402 delete [] pArgBuffer;
403 delete [] pKeyBuffer;
404
405 rtl_cipher_destroy(aCipher);
406 #endif
407 }
408
409 void encode_001()
410 {
411 test_encode(0,0,0);
412 test_encode(1,0,0);
413 test_encode(0,1,0);
414 test_encode(1,1,0);
415
416 test_encode(0,0,1);
417 test_encode(1,0,1);
418 test_encode(0,1,1);
419 test_encode(1,1,1);
420 }
421
422 // Change the following lines only, if you add, remove or rename
423 // member functions of the current class,
424 // because these macros are need by auto register mechanism.
425
426 CPPUNIT_TEST_SUITE(encode);
427 CPPUNIT_TEST(encode_001);
428 CPPUNIT_TEST_SUITE_END();
429 }; // class encode
430
431 class encodeBF : public CppUnit::TestFixture
432 {
433 public:
434
435 void encodeBF_001()
436 {
437 }
438 // Change the following lines only, if you add, remove or rename
439 // member functions of the current class,
440 // because these macros are need by auto register mechanism.
441
442 CPPUNIT_TEST_SUITE(encodeBF);
443 CPPUNIT_TEST(encodeBF_001);
444 CPPUNIT_TEST_SUITE_END();
445 }; // class encodeBF
446
447 class init : public CppUnit::TestFixture
448 {
449 public:
450
451 void init_001()
452 {
453 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
454 #if defined LIBO_CIPHER_OPENSSL_BACKEND
455 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
456 #else
457 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
458
459 sal_uInt32 nKeyLen = 16;
460 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
461 memset(pKeyBuffer, 0, nKeyLen);
462
463 sal_uInt32 nArgLen = 16;
464 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
465 memset(pArgBuffer, 0, nArgLen);
466
467 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
468 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
469
470 delete [] pArgBuffer;
471 delete [] pKeyBuffer;
472
473 rtl_cipher_destroy(aCipher);
474 #endif
475 }
476
477 void init_002()
478 {
479 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
480 #if defined LIBO_CIPHER_OPENSSL_BACKEND
481 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
482 #else
483 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
484
485 sal_uInt32 nKeyLen = 16;
486 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
487 memset(pKeyBuffer, 0, nKeyLen);
488 pKeyBuffer[0] = 1;
489
490 sal_uInt32 nArgLen = 16;
491 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
492 memset(pArgBuffer, 0, nArgLen);
493
494 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
495 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
496
497 delete [] pArgBuffer;
498 delete [] pKeyBuffer;
499
500 rtl_cipher_destroy(aCipher);
501 #endif
502 }
503 void init_003()
504 {
505 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
506 #if defined LIBO_CIPHER_OPENSSL_BACKEND
507 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
508 #else
509 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
510
511 sal_uInt32 nKeyLen = 16;
512 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
513 memset(pKeyBuffer, 0, nKeyLen);
514
515 sal_uInt32 nArgLen = 16;
516 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
517 memset(pArgBuffer, 0, nArgLen);
518 pArgBuffer[0] = 1;
519
520 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
521 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
522
523 delete [] pArgBuffer;
524 delete [] pKeyBuffer;
525
526 rtl_cipher_destroy(aCipher);
527 #endif
528 }
529 void init_004()
530 {
531 rtlCipher aCipher = rtl_cipher_create(rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeECB);
532 #if defined LIBO_CIPHER_OPENSSL_BACKEND
533 CPPUNIT_ASSERT_EQUAL(rtlCipher(nullptr), aCipher);
534 #else
535 CPPUNIT_ASSERT_MESSAGE("create failed.", aCipher != nullptr);
536
537 sal_uInt32 nKeyLen = 16;
538 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
539 memset(pKeyBuffer, 0, nKeyLen);
540 pKeyBuffer[0] = 1;
541
542 sal_uInt32 nArgLen = 16;
543 sal_uInt8 *pArgBuffer = new sal_uInt8[ nArgLen ];
544 memset(pArgBuffer, 0, nArgLen);
545 pArgBuffer[0] = 1;
546
547 rtlCipherError aError = rtl_cipher_init(aCipher, rtl_Cipher_DirectionEncode, pKeyBuffer, nKeyLen, pArgBuffer, nArgLen);
548 CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong init", rtl_Cipher_E_None, aError);
549
550 delete [] pArgBuffer;
551 delete [] pKeyBuffer;
552
553 rtl_cipher_destroy(aCipher);
554 #endif
555 }
556 // Change the following lines only, if you add, remove or rename
557 // member functions of the current class,
558 // because these macros are need by auto register mechanism.
559
560 CPPUNIT_TEST_SUITE(init);
561 CPPUNIT_TEST(init_001);
562 CPPUNIT_TEST(init_002);
563 CPPUNIT_TEST(init_003);
564 CPPUNIT_TEST(init_004);
565 CPPUNIT_TEST_SUITE_END();
566 }; // class init
567
568 class initBF : public CppUnit::TestFixture
569 {
570 public:
571
572 void initBF_001()
573 {
574 // seems to be the same as init, so empty
575 }
576
577 // Change the following lines only, if you add, remove or rename
578 // member functions of the current class,
579 // because these macros are need by auto register mechanism.
580
581 CPPUNIT_TEST_SUITE(initBF);
582 CPPUNIT_TEST(initBF_001);
583 CPPUNIT_TEST_SUITE_END();
584 }; // class initBF
585
586 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::create);
587 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::createBF);
588 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::decode);
589 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::decodeBF);
590 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::destroy);
591 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::destroyBF);
592 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::encode);
593 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::encodeBF);
594 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::init);
595 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_cipher::initBF);
596
597 } // namespace rtl_cipher
598
599 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */