update dev300-m57
[ooovba.git] / sal / qa / rtl / digest / rtl_digest.cxx
blobc986536bc999aadc1086f50226fac71aaa935ed5
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_digest.cxx,v $
10 * $Revision: 1.5 $
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"
34 #include <cppunit/simpleheader.hxx>
36 #include <rtl/digest.h>
37 #include <rtl/ustring.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <rtl/strbuf.hxx>
41 // sample, how to use digest
43 rtl::OUString CreateMD5FromString( const rtl::OUString& aMsg )
45 // PRE: aStr "file"
46 // BACK: Str "ababab....0f" Hexcode String
48 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
49 if ( handle > 0 )
51 const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr();
52 sal_uInt32 nSize = ( aMsg.getLength() * sizeof( sal_Unicode ));
53 sal_uInt32 nMD5KeyLen = rtl_digest_queryLength( handle );
54 sal_uInt8* pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ];
56 rtl_digest_init( handle, pData, nSize );
57 rtl_digest_update( handle, pData, nSize );
58 rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen );
59 rtl_digest_destroy( handle );
61 // Create hex-value string from the MD5 value to keep the string size minimal
62 rtl::OUStringBuffer aBuffer( nMD5KeyLen * 2 + 1 );
63 for ( sal_uInt32 i = 0; i < nMD5KeyLen; i++ )
64 aBuffer.append( (sal_Int32)pMD5KeyBuffer[i], 16 );
66 delete [] pMD5KeyBuffer;
67 return aBuffer.makeStringAndClear();
70 return rtl::OUString();
73 // -----------------------------------------------------------------------------
74 namespace rtl_digest
77 rtl::OString sSampleString = "This is a sample sentence, which we use to check some crypto functions in sal.";
78 rtl::OString sSampleString_MD2 = "647ee6c9d4aa5fdd374ed9d7a156acbf";
79 rtl::OString sSampleString_MD5 = "b16b903e6fc0b62ae389013ed93fe531";
80 rtl::OString sSampleString_SHA = "eab2814429b2613301c8a077b806af3680548914";
81 rtl::OString sSampleString_SHA1 = "2bc5bdb7506a2cdc2fd27fc8b9889343012d5008";
82 rtl::OString sSampleString_HMAC_MD5 = "dd9cba48c972fba0a882baa72b079674";
83 rtl::OString sSampleString_HMAC_SHA1 = "5d7f43ce6abd1de4438d7e69e01495864490cf3e";
85 rtl::OString sSampleString_only_one_diff = "This is a sample sentence. which we use to check some crypto functions in sal.";
87 class create : public CppUnit::TestFixture
89 public:
90 // initialise your test code values here.
91 void setUp()
95 void tearDown()
99 void create_001()
101 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
102 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle != 0);
103 rtl_digest_destroy( handle );
105 void create_002()
107 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
108 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", handle != 0);
109 rtl_digest_destroy( handle );
111 void create_003()
113 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA );
114 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA", handle != 0);
115 rtl_digest_destroy( handle );
117 void create_004()
119 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 );
120 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA1", handle != 0);
121 rtl_digest_destroy( handle );
123 void create_005()
125 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 );
126 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_MD5", handle != 0);
127 rtl_digest_destroy( handle );
129 void create_006()
131 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 );
132 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_SHA1", handle != 0);
133 rtl_digest_destroy( handle );
136 void create_007()
138 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid );
139 t_print("Handle is %x\n", handle);
140 CPPUNIT_ASSERT_MESSAGE("create with NULL", handle == 0);
141 rtl_digest_destroy( handle );
144 // Change the following lines only, if you add, remove or rename
145 // member functions of the current class,
146 // because these macros are need by auto register mechanism.
148 CPPUNIT_TEST_SUITE(create);
149 CPPUNIT_TEST(create_001);
150 CPPUNIT_TEST(create_002);
151 CPPUNIT_TEST(create_003);
152 CPPUNIT_TEST(create_004);
153 CPPUNIT_TEST(create_005);
154 CPPUNIT_TEST(create_006);
155 CPPUNIT_TEST(create_007);
156 CPPUNIT_TEST_SUITE_END();
157 }; // class create
162 // -----------------------------------------------------------------------------
164 class createMD5 : public CppUnit::TestFixture
166 public:
167 // initialise your test code values here.
168 void setUp()
172 void tearDown()
176 void createMD5_001()
178 rtlDigest handle = rtl_digest_createMD5();
180 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
181 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5 == aAlgo);
183 rtl_digest_destroy( handle );
185 CPPUNIT_TEST_SUITE(createMD5);
186 CPPUNIT_TEST(createMD5_001);
187 CPPUNIT_TEST_SUITE_END();
188 }; // class create
191 // -----------------------------------------------------------------------------
193 class createMD2 : public CppUnit::TestFixture
195 public:
196 // initialise your test code values here.
197 void setUp()
201 void tearDown()
205 void createMD2_001()
207 rtlDigest handle = rtl_digest_createMD2( );
209 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
210 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2 == aAlgo);
212 rtl_digest_destroy( handle );
214 CPPUNIT_TEST_SUITE(createMD2);
215 CPPUNIT_TEST(createMD2_001);
216 CPPUNIT_TEST_SUITE_END();
217 }; // class create
219 // -----------------------------------------------------------------------------
221 class createSHA : public CppUnit::TestFixture
223 public:
224 // initialise your test code values here.
225 void setUp()
229 void tearDown()
233 void createSHA_001()
235 rtlDigest handle = rtl_digest_createSHA( );
237 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
238 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA == aAlgo);
240 rtl_digest_destroy( handle );
242 CPPUNIT_TEST_SUITE(createSHA);
243 CPPUNIT_TEST(createSHA_001);
244 CPPUNIT_TEST_SUITE_END();
245 }; // class create
246 // -----------------------------------------------------------------------------
248 class createSHA1 : public CppUnit::TestFixture
250 public:
251 // initialise your test code values here.
252 void setUp()
256 void tearDown()
260 void createSHA1_001()
262 rtlDigest handle = rtl_digest_createSHA1();
264 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
265 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1 == aAlgo);
267 rtl_digest_destroy( handle );
269 CPPUNIT_TEST_SUITE(createSHA1);
270 CPPUNIT_TEST(createSHA1_001);
271 CPPUNIT_TEST_SUITE_END();
272 }; // class create
273 // -----------------------------------------------------------------------------
275 class createHMAC_MD5 : public CppUnit::TestFixture
277 public:
278 // initialise your test code values here.
279 void setUp()
283 void tearDown()
287 void createHMAC_MD5_001()
289 rtlDigest handle = rtl_digest_createHMAC_MD5();
291 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
292 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5 == aAlgo);
294 rtl_digest_destroy( handle );
296 CPPUNIT_TEST_SUITE(createHMAC_MD5);
297 CPPUNIT_TEST(createHMAC_MD5_001);
298 CPPUNIT_TEST_SUITE_END();
299 }; // class create
300 // -----------------------------------------------------------------------------
302 class createHMAC_SHA1 : public CppUnit::TestFixture
304 public:
305 // initialise your test code values here.
306 void setUp()
310 void tearDown()
314 void createHMAC_SHA1_001()
316 rtlDigest handle = rtl_digest_createHMAC_SHA1();
318 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
319 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1 == aAlgo);
321 rtl_digest_destroy( handle );
325 CPPUNIT_TEST_SUITE(createHMAC_SHA1);
326 CPPUNIT_TEST(createHMAC_SHA1_001);
327 CPPUNIT_TEST_SUITE_END();
328 }; // class create
330 // -----------------------------------------------------------------------------
332 class queryAlgorithm : public CppUnit::TestFixture
334 public:
335 // initialise your test code values here.
336 void setUp()
340 void tearDown()
344 void query_001()
346 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
348 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
349 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5 == aAlgo);
351 rtl_digest_destroy( handle );
353 void query_002()
355 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
357 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
358 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2 == aAlgo);
360 rtl_digest_destroy( handle );
362 void query_003()
364 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA );
366 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
367 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA == aAlgo);
369 rtl_digest_destroy( handle );
371 void query_004()
373 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 );
375 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
376 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1 == aAlgo);
378 rtl_digest_destroy( handle );
380 void query_005()
382 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 );
384 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
385 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5 == aAlgo);
387 rtl_digest_destroy( handle );
389 void query_006()
391 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 );
393 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
394 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1 == aAlgo);
396 rtl_digest_destroy( handle );
398 void query_007()
400 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid );
402 rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle);
403 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmInvalid == aAlgo);
405 rtl_digest_destroy( handle );
408 // Change the following lines only, if you add, remove or rename
409 // member functions of the current class,
410 // because these macros are need by auto register mechanism.
412 CPPUNIT_TEST_SUITE(queryAlgorithm);
413 CPPUNIT_TEST( query_001 );
414 CPPUNIT_TEST( query_002 );
415 CPPUNIT_TEST( query_003 );
416 CPPUNIT_TEST( query_004 );
417 CPPUNIT_TEST( query_005 );
418 CPPUNIT_TEST( query_006 );
419 CPPUNIT_TEST( query_007 );
420 CPPUNIT_TEST_SUITE_END();
421 }; // class create
424 // -----------------------------------------------------------------------------
425 class queryLength : public CppUnit::TestFixture
427 public:
428 // initialise your test code values here.
429 void setUp()
433 void tearDown()
437 void queryLength_MD5()
439 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
441 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
442 // t_print("nAlgoLength:=%d\n", nAlgoLength);
443 CPPUNIT_ASSERT_MESSAGE("query Length", RTL_DIGEST_LENGTH_MD5 == nAlgoLength);
445 rtl_digest_destroy( handle );
447 void queryLength_MD2()
449 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
451 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
452 // t_print("nAlgoLength:=%d\n", nAlgoLength);
453 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_MD2 == nAlgoLength);
455 rtl_digest_destroy( handle );
457 void queryLength_SHA()
459 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA );
461 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
462 // t_print("nAlgoLength:=%d\n", nAlgoLength);
463 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA == nAlgoLength);
465 rtl_digest_destroy( handle );
467 void queryLength_SHA1()
469 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 );
471 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
472 // t_print("nAlgoLength:=%d\n", nAlgoLength);
473 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA1 == nAlgoLength);
475 rtl_digest_destroy( handle );
477 void queryLength_HMAC_MD5()
479 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 );
481 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
482 // t_print("nAlgoLength:=%d\n", nAlgoLength);
483 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_MD5 == nAlgoLength);
485 rtl_digest_destroy( handle );
487 void queryLength_HMAC_SHA1()
489 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 );
491 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
492 // t_print("nAlgoLength:=%d\n", nAlgoLength);
493 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_SHA1 == nAlgoLength);
495 rtl_digest_destroy( handle );
498 void queryLength_Illegal()
500 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid );
502 sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle);
503 // t_print("nAlgoLength:=%d\n", nAlgoLength);
504 CPPUNIT_ASSERT_MESSAGE("query length", 0 == nAlgoLength);
506 rtl_digest_destroy( handle );
509 // Change the following lines only, if you add, remove or rename
510 // member functions of the current class,
511 // because these macros are need by auto register mechanism.
513 CPPUNIT_TEST_SUITE(queryLength);
514 CPPUNIT_TEST( queryLength_MD2 );
515 CPPUNIT_TEST( queryLength_MD5 );
516 CPPUNIT_TEST( queryLength_SHA );
517 CPPUNIT_TEST( queryLength_SHA1 );
518 CPPUNIT_TEST( queryLength_HMAC_MD5 );
519 CPPUNIT_TEST( queryLength_HMAC_SHA1 );
520 CPPUNIT_TEST( queryLength_Illegal );
521 CPPUNIT_TEST_SUITE_END();
522 }; // class create
524 // -----------------------------------------------------------------------------
526 rtl::OString createHex(sal_uInt8 *_pMD5KeyBuffer, sal_uInt32 _nMD5KeyLen)
528 // Create hex-value string from the MD5 value to keep the string size minimal
529 rtl::OStringBuffer aBuffer( _nMD5KeyLen * 2 + 1 );
530 for ( sal_uInt32 i = 0; i < _nMD5KeyLen; i++ )
532 sal_Int32 nValue = (sal_Int32)_pMD5KeyBuffer[i];
533 if (nValue < 16) // maximul hex value for 1 byte
535 aBuffer.append( sal_Int32(0), 16 /* radix */ );
537 aBuffer.append( nValue, 16 /* radix */ );
540 return aBuffer.makeStringAndClear();
544 // -----------------------------------------------------------------------------
545 class init : public CppUnit::TestFixture
547 public:
548 // initialise your test code values here.
549 void setUp()
553 void tearDown()
557 void init_000()
559 rtlDigest handle = NULL;
561 rtlDigestError aError = rtl_digest_init(handle, NULL, 0);
563 CPPUNIT_ASSERT_MESSAGE("init(NULL, 0, 0)", aError == rtl_Digest_E_Argument);
566 void init_001()
568 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
570 rtlDigestError aError = rtl_digest_init(handle, NULL, 0);
572 CPPUNIT_ASSERT_MESSAGE("init(handle, 0, 0)", aError == rtl_Digest_E_None);
574 rtl_digest_destroy( handle );
577 // ------------------------------------
578 void init_MD2()
580 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
582 rtl::OString aMsg = sSampleString;
583 const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr();
584 sal_uInt32 nSize = ( aMsg.getLength() );
586 rtlDigestError aError = rtl_digest_init(handle, pData, nSize);
588 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None);
590 rtl_digest_update( handle, pData, nSize );
592 sal_uInt32 nKeyLen = rtl_digest_queryLength( handle );
593 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
595 rtl_digest_get( handle, pKeyBuffer, nKeyLen );
596 rtl::OString aSum = createHex(pKeyBuffer, nKeyLen);
597 delete [] pKeyBuffer;
599 t_print("MD2 Sum: %s\n", aSum.getStr());
600 // LLA: how to check right values
601 // samples?
603 rtl_digest_destroy( handle );
606 void init_MD5()
608 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
610 rtl::OString aMsg = sSampleString;
611 const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr();
612 sal_uInt32 nSize = ( aMsg.getLength() );
614 rtlDigestError aError = rtl_digest_init(handle, pData, nSize);
616 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None);
618 rtl_digest_update( handle, pData, nSize );
620 sal_uInt32 nKeyLen = rtl_digest_queryLength( handle );
621 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
623 rtl_digest_get( handle, pKeyBuffer, nKeyLen );
624 rtl::OString aSum = createHex(pKeyBuffer, nKeyLen);
625 delete [] pKeyBuffer;
627 t_print("MD5 Sum: %s\n", aSum.getStr());
628 // LLA: how to check right values
629 // samples?
631 rtl_digest_destroy( handle );
634 void init_SHA()
636 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA );
638 rtl::OString aMsg = sSampleString;
639 const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr();
640 sal_uInt32 nSize = ( aMsg.getLength() );
642 rtlDigestError aError = rtl_digest_init(handle, pData, nSize);
644 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None);
646 rtl_digest_update( handle, pData, nSize );
648 sal_uInt32 nKeyLen = rtl_digest_queryLength( handle );
649 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
651 rtl_digest_get( handle, pKeyBuffer, nKeyLen );
652 rtl::OString aSum = createHex(pKeyBuffer, nKeyLen);
653 delete [] pKeyBuffer;
655 t_print("SHA Sum: %s\n", aSum.getStr());
656 // LLA: how to check right values
657 // samples?
659 rtl_digest_destroy( handle );
661 void init_SHA1()
663 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 );
665 rtl::OString aMsg = sSampleString;
666 const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr();
667 sal_uInt32 nSize = ( aMsg.getLength() );
669 rtlDigestError aError = rtl_digest_init(handle, pData, nSize);
671 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None);
673 rtl_digest_update( handle, pData, nSize );
675 sal_uInt32 nKeyLen = rtl_digest_queryLength( handle );
676 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
678 rtl_digest_get( handle, pKeyBuffer, nKeyLen );
679 rtl::OString aSum = createHex(pKeyBuffer, nKeyLen);
680 delete [] pKeyBuffer;
682 t_print("SHA1 Sum: %s\n", aSum.getStr());
683 // LLA: how to check right values
684 // samples?
686 rtl_digest_destroy( handle );
688 void init_HMAC_MD5()
690 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 );
692 rtl::OString aMsg = sSampleString;
693 const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr();
694 sal_uInt32 nSize = ( aMsg.getLength() );
696 sal_uInt32 nKeyLen = rtl_digest_queryLength( handle );
697 CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen );
699 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
700 CPPUNIT_ASSERT( pKeyBuffer );
701 memset(pKeyBuffer, 0, nKeyLen);
703 rtlDigestError aError = rtl_digest_init(handle, pKeyBuffer, nKeyLen );
705 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None);
707 rtl_digest_update( handle, pData, nSize );
709 rtl_digest_get( handle, pKeyBuffer, nKeyLen );
710 rtl::OString aSum = createHex(pKeyBuffer, nKeyLen);
711 delete [] pKeyBuffer;
713 t_print("HMAC_MD5 Sum: %s\n", aSum.getStr());
714 // LLA: how to check right values
715 // samples?
717 rtl_digest_destroy( handle );
719 void init_HMAC_SHA1()
721 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 );
723 rtl::OString aMsg = sSampleString;
724 const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr();
725 sal_uInt32 nSize = ( aMsg.getLength() );
727 sal_uInt32 nKeyLen = rtl_digest_queryLength( handle );
728 CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen );
730 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
731 CPPUNIT_ASSERT( pKeyBuffer );
732 memset(pKeyBuffer, 0, nKeyLen);
734 rtlDigestError aError = rtl_digest_init(handle, pKeyBuffer, nKeyLen );
736 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None);
738 rtl_digest_update( handle, pData, nSize );
740 rtl_digest_get( handle, pKeyBuffer, nKeyLen );
741 rtl::OString aSum = createHex(pKeyBuffer, nKeyLen);
742 delete [] pKeyBuffer;
744 t_print("HMAC_SHA1 Sum: %s\n", aSum.getStr());
745 // LLA: how to check right values
746 // samples?
748 rtl_digest_destroy( handle );
752 // Change the following lines only, if you add, remove or rename
753 // member functions of the current class,
754 // because these macros are need by auto register mechanism.
756 CPPUNIT_TEST_SUITE(init);
757 CPPUNIT_TEST( init_000 );
758 CPPUNIT_TEST( init_001 );
759 CPPUNIT_TEST( init_MD2 );
760 CPPUNIT_TEST( init_MD5 );
761 CPPUNIT_TEST( init_SHA );
762 CPPUNIT_TEST( init_SHA1 );
763 CPPUNIT_TEST( init_HMAC_MD5 );
764 CPPUNIT_TEST( init_HMAC_SHA1 );
765 CPPUNIT_TEST_SUITE_END();
766 }; // class init
768 // ------------------------------------
770 rtl::OString getMD5Sum(rtl::OString const& _aMsg )
772 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
774 const sal_uInt8 *pData = (const sal_uInt8*)_aMsg.getStr();
775 sal_uInt32 nSize = ( _aMsg.getLength() );
777 rtl_digest_init(handle, pData, nSize);
778 rtl_digest_update( handle, pData, nSize );
780 sal_uInt32 nMD5KeyLen = rtl_digest_queryLength( handle );
781 sal_uInt8 *pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ];
783 rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen );
784 rtl::OString aMD5Sum = createHex(pMD5KeyBuffer, nMD5KeyLen);
785 delete [] pMD5KeyBuffer;
787 rtl_digest_destroy( handle );
788 return aMD5Sum;
791 // -----------------------------------------------------------------------------
793 class equalTests : public CppUnit::TestFixture
795 public:
796 // initialise your test code values here.
797 void setUp()
801 void tearDown()
805 // ------------------------------------
806 void equal_001()
808 rtl::OString aMsg1 = sSampleString;
809 rtl::OString aMsg2 = sSampleString;
811 rtl::OString aMsgMD5Sum1 = getMD5Sum(aMsg1);
812 rtl::OString aMsgMD5Sum2 = getMD5Sum(aMsg2);
814 CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1.getLength() == 32 && aMsgMD5Sum2.getLength() == 32 );
815 CPPUNIT_ASSERT_MESSAGE("source is the same, dest must be also the same", aMsgMD5Sum1.equals(aMsgMD5Sum2) == sal_True);
817 // ------------------------------------
818 void equal_002()
820 rtl::OString aMsg1 = sSampleString;
821 rtl::OString aMsg2 = sSampleString_only_one_diff;
823 rtl::OString aMsgMD5Sum1 = getMD5Sum(aMsg1);
824 rtl::OString aMsgMD5Sum2 = getMD5Sum(aMsg2);
826 CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1.getLength() == 32 && aMsgMD5Sum2.getLength() == 32 );
827 CPPUNIT_ASSERT_MESSAGE("differ only in one char", aMsgMD5Sum1.equals(aMsgMD5Sum2) == sal_False);
830 // Change the following lines only, if you add, remove or rename
831 // member functions of the current class,
832 // because these macros are need by auto register mechanism.
834 CPPUNIT_TEST_SUITE(equalTests);
835 CPPUNIT_TEST( equal_001 );
836 CPPUNIT_TEST( equal_002 );
837 CPPUNIT_TEST_SUITE_END();
838 }; // class create
841 // -----------------------------------------------------------------------------
842 class digest_MD2 : public CppUnit::TestFixture
844 public:
845 // initialise your test code values here.
846 void setUp()
850 void tearDown()
854 // ------------------------------------
855 void MD2_001()
857 rtl::OString aMsg1 = sSampleString;
859 sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_MD2 ];
860 CPPUNIT_ASSERT( pBuffer );
861 memset(pBuffer, 0, RTL_DIGEST_LENGTH_MD2 );
863 sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr();
864 sal_Int32 nLen = aMsg1.getLength();
866 rtlDigestError aError = rtl_digest_MD2(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_MD2);
868 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
870 rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD2);
871 t_print("Decrypt MD2: %s\n", aStr.getStr());
872 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD2) );
874 delete [] pBuffer;
877 // Change the following lines only, if you add, remove or rename
878 // member functions of the current class,
879 // because these macros are need by auto register mechanism.
881 CPPUNIT_TEST_SUITE(digest_MD2);
882 CPPUNIT_TEST( MD2_001 );
883 CPPUNIT_TEST_SUITE_END();
884 }; // class create
885 // -----------------------------------------------------------------------------
886 class digest_MD5 : public CppUnit::TestFixture
888 public:
889 // initialise your test code values here.
890 void setUp()
894 void tearDown()
897 // ------------------------------------
898 void MD5_001()
900 rtl::OString aMsg1 = sSampleString;
902 sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_MD5 ];
903 CPPUNIT_ASSERT( pBuffer );
904 memset(pBuffer, 0, RTL_DIGEST_LENGTH_MD5 );
906 sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr();
907 sal_Int32 nLen = aMsg1.getLength();
909 rtlDigestError aError = rtl_digest_MD5(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_MD5);
911 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
913 rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD5);
914 t_print("Decrypt MD5: %s\n", aStr.getStr());
915 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD5) );
917 delete [] pBuffer;
920 // Change the following lines only, if you add, remove or rename
921 // member functions of the current class,
922 // because these macros are need by auto register mechanism.
924 CPPUNIT_TEST_SUITE(digest_MD5);
925 CPPUNIT_TEST( MD5_001 );
926 CPPUNIT_TEST_SUITE_END();
927 }; // class create
929 // -----------------------------------------------------------------------------
930 class digest_SHA : public CppUnit::TestFixture
932 public:
933 // initialise your test code values here.
934 void setUp()
938 void tearDown()
942 // ------------------------------------
943 void SHA_001()
945 rtl::OString aMsg1 = sSampleString;
947 sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_SHA ];
948 CPPUNIT_ASSERT( pBuffer );
949 memset(pBuffer, 0, RTL_DIGEST_LENGTH_SHA);
951 sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr();
952 sal_Int32 nLen = aMsg1.getLength();
954 rtlDigestError aError = rtl_digest_SHA(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_SHA);
956 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
958 rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA);
959 t_print("Decrypt SHA: %s\n", aStr.getStr());
960 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA) );
962 delete [] pBuffer;
965 // Change the following lines only, if you add, remove or rename
966 // member functions of the current class,
967 // because these macros are need by auto register mechanism.
969 CPPUNIT_TEST_SUITE(digest_SHA);
970 CPPUNIT_TEST( SHA_001 );
971 CPPUNIT_TEST_SUITE_END();
972 }; // class create
974 // -----------------------------------------------------------------------------
975 class digest_SHA1 : public CppUnit::TestFixture
977 public:
978 // initialise your test code values here.
979 void setUp()
983 void tearDown()
987 // ------------------------------------
988 void SHA1_001()
990 rtl::OString aMsg1 = sSampleString;
992 sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_SHA1 ];
993 CPPUNIT_ASSERT( pBuffer );
994 memset(pBuffer, 0, RTL_DIGEST_LENGTH_SHA1);
996 sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr();
997 sal_Int32 nLen = aMsg1.getLength();
999 rtlDigestError aError = rtl_digest_SHA1(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_SHA1);
1001 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
1003 rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA1);
1004 t_print("Decrypt SHA1: %s\n", aStr.getStr());
1005 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA1) );
1007 delete [] pBuffer;
1009 // Change the following lines only, if you add, remove or rename
1010 // member functions of the current class,
1011 // because these macros are need by auto register mechanism.
1013 CPPUNIT_TEST_SUITE(digest_SHA1);
1014 CPPUNIT_TEST( SHA1_001 );
1015 CPPUNIT_TEST_SUITE_END();
1016 }; // class create
1017 // -----------------------------------------------------------------------------
1018 class digest_HMAC_MD5 : public CppUnit::TestFixture
1020 public:
1021 // initialise your test code values here.
1022 void setUp()
1026 void tearDown()
1030 // ------------------------------------
1031 void HMAC_MD5_001()
1033 rtl::OString aMsg1 = sSampleString;
1035 sal_uInt8 *pKeyBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_MD5 ];
1036 CPPUNIT_ASSERT( pKeyBuffer );
1037 memset(pKeyBuffer, 0, RTL_DIGEST_LENGTH_HMAC_MD5);
1039 sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_MD5 ];
1040 CPPUNIT_ASSERT( pBuffer );
1041 memset(pBuffer, 0, RTL_DIGEST_LENGTH_HMAC_MD5);
1043 sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr();
1044 sal_Int32 nLen = aMsg1.getLength();
1046 rtlDigestError aError = rtl_digest_HMAC_MD5(pKeyBuffer, RTL_DIGEST_LENGTH_HMAC_MD5, pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5);
1048 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
1050 rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5);
1051 t_print("Decrypt HMAC_MD5: %s\n", aStr.getStr());
1052 CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_MD5) );
1054 delete [] pBuffer;
1056 // Change the following lines only, if you add, remove or rename
1057 // member functions of the current class,
1058 // because these macros are need by auto register mechanism.
1060 CPPUNIT_TEST_SUITE(digest_HMAC_MD5);
1061 CPPUNIT_TEST( HMAC_MD5_001 );
1062 CPPUNIT_TEST_SUITE_END();
1063 }; // class create
1064 // -----------------------------------------------------------------------------
1065 class digest_HMAC_SHA1 : public CppUnit::TestFixture
1067 public:
1068 // initialise your test code values here.
1069 void setUp()
1073 void tearDown()
1077 // ------------------------------------
1078 void HMAC_SHA1_001()
1080 rtl::OString aMsg1 = sSampleString;
1082 sal_uInt8 *pKeyBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_SHA1 ];
1083 CPPUNIT_ASSERT( pKeyBuffer );
1084 memset(pKeyBuffer, 0, RTL_DIGEST_LENGTH_HMAC_SHA1);
1086 sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_SHA1 ];
1087 CPPUNIT_ASSERT( pBuffer );
1088 memset(pBuffer, 0, RTL_DIGEST_LENGTH_HMAC_SHA1);
1090 sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr();
1091 sal_Int32 nLen = aMsg1.getLength();
1093 rtlDigestError aError = rtl_digest_HMAC_SHA1(pKeyBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1, pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1);
1095 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
1097 rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1);
1098 t_print("Decrypt HMAC_SHA1: %s\n", aStr.getStr());
1099 CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_SHA1) );
1101 delete [] pBuffer;
1104 // Change the following lines only, if you add, remove or rename
1105 // member functions of the current class,
1106 // because these macros are need by auto register mechanism.
1108 CPPUNIT_TEST_SUITE(digest_HMAC_SHA1);
1109 CPPUNIT_TEST( HMAC_SHA1_001 );
1110 CPPUNIT_TEST_SUITE_END();
1111 }; // class create
1112 // -----------------------------------------------------------------------------
1113 class digest_PBKDF2 : public CppUnit::TestFixture
1115 public:
1116 // initialise your test code values here.
1117 void setUp()
1121 void tearDown()
1125 // ------------------------------------
1126 rtl::OString /* key */ run_check_PBKDF2(rtl::OString const& _sPassword, bool _bClearSalt, sal_uInt32 _nCount)
1128 sal_uInt32 nKeyLen = RTL_DIGEST_LENGTH_HMAC_SHA1;
1129 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
1130 CPPUNIT_ASSERT( pKeyBuffer );
1131 memset(pKeyBuffer, 0, nKeyLen);
1133 sal_uInt8 *pPassword = (sal_uInt8*)_sPassword.getStr();
1134 sal_Int32 nPasswordLen = _sPassword.getLength();
1136 sal_uInt32 nSaltDataLen = RTL_DIGEST_LENGTH_HMAC_SHA1;
1137 sal_uInt8 *pSaltData = new sal_uInt8[ nSaltDataLen ];
1138 CPPUNIT_ASSERT( pSaltData );
1139 memset(pSaltData, 0, nSaltDataLen);
1141 if (! _bClearSalt)
1143 // wilful contamination
1144 pSaltData[0] = 1;
1147 rtlDigestError aError = rtl_digest_PBKDF2(pKeyBuffer, nKeyLen, pPassword, nPasswordLen, pSaltData, nSaltDataLen, _nCount);
1149 CPPUNIT_ASSERT(aError == rtl_Digest_E_None );
1151 rtl::OString aKey = createHex(pKeyBuffer, nKeyLen);
1152 t_print("Key: %s\n", aKey.getStr());
1154 // rtl::OString sSalt = createHex(pSaltData, nSaltDataLen);
1155 // t_print("Salt: %s\n", sSalt.getStr());
1157 // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) );
1159 delete [] pSaltData;
1160 delete [] pKeyBuffer;
1161 return aKey;
1164 void PBKDF2_001()
1166 rtl::OString aPassword = "Password";
1168 // all permutations
1169 run_check_PBKDF2(aPassword, false, 1);
1170 run_check_PBKDF2(aPassword, false, 2);
1171 run_check_PBKDF2(aPassword, true, 1);
1172 run_check_PBKDF2(aPassword, true, 2);
1173 run_check_PBKDF2(aPassword, false, 3);
1174 run_check_PBKDF2(aPassword, false, 4);
1175 run_check_PBKDF2(aPassword, true, 3);
1176 run_check_PBKDF2(aPassword, true, 4);
1178 // Change the following lines only, if you add, remove or rename
1179 // member functions of the current class,
1180 // because these macros are need by auto register mechanism.
1182 CPPUNIT_TEST_SUITE(digest_PBKDF2);
1183 CPPUNIT_TEST( PBKDF2_001 );
1184 CPPUNIT_TEST_SUITE_END();
1185 }; // class create
1186 // -----------------------------------------------------------------------------
1188 class update : public CppUnit::TestFixture
1190 public:
1191 // initialise your test code values here.
1192 void setUp()
1196 void tearDown()
1200 void update_000()
1202 rtlDigest aHandle = NULL;
1203 rtlDigestError aError = rtl_digest_update(aHandle, NULL, 0);
1204 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1207 void updateMD2_000()
1209 rtlDigest aHandle = NULL;
1210 rtlDigestError aError = rtl_digest_updateMD2(aHandle, NULL, 0);
1211 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1214 void updateMD2_001()
1216 rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
1217 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0);
1219 rtl::OString aMsg = sSampleString;
1220 const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr();
1222 rtlDigestError aError = rtl_digest_updateMD2(aHandle, NULL, 0);
1223 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument );
1225 /* rtlDigestError */ aError = rtl_digest_updateMD2(aHandle, pData, 0);
1226 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_None );
1228 rtl_digest_destroyMD2(aHandle);
1230 void updateMD5_000()
1232 rtlDigest aHandle = NULL;
1233 rtlDigestError aError = rtl_digest_updateMD5(aHandle, NULL, 0);
1234 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1237 void updateMD5_001()
1239 // use wrong Algorithm!!! This is volitional!
1240 rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
1241 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0);
1243 rtl::OString aMsg = sSampleString;
1244 const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr();
1245 sal_uInt32 nSize = ( aMsg.getLength() );
1247 rtlDigestError aError = rtl_digest_updateMD5(aHandle, pData, nSize);
1248 CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError == rtl_Digest_E_Algorithm );
1250 rtl_digest_destroyMD5(aHandle);
1253 void updateMD5_002()
1255 rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
1256 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != 0);
1258 rtl::OString aMsg = sSampleString;
1259 const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr();
1261 rtlDigestError aError = rtl_digest_updateMD5(aHandle, NULL, 0);
1262 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument );
1264 /* rtlDigestError */ aError = rtl_digest_updateMD5(aHandle, pData, 0);
1265 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_None );
1267 rtl_digest_destroyMD5(aHandle);
1270 void updateSHA_000()
1272 rtlDigest aHandle = NULL;
1273 rtlDigestError aError = rtl_digest_updateSHA(aHandle, NULL, 0);
1274 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1277 void updateSHA1_000()
1279 rtlDigest aHandle = NULL;
1280 rtlDigestError aError = rtl_digest_updateSHA1(aHandle, NULL, 0);
1281 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1284 void updateHMAC_MD5_000()
1286 rtlDigest aHandle = NULL;
1287 rtlDigestError aError = rtl_digest_updateHMAC_MD5(aHandle, NULL, 0);
1288 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1291 void updateHMAC_SHA1_000()
1293 rtlDigest aHandle = NULL;
1294 rtlDigestError aError = rtl_digest_updateHMAC_SHA1(aHandle, NULL, 0);
1295 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1298 // Change the following lines only, if you add, remove or rename
1299 // member functions of the current class,
1300 // because these macros are need by auto register mechanism.
1302 CPPUNIT_TEST_SUITE(update);
1303 CPPUNIT_TEST(update_000);
1304 CPPUNIT_TEST(updateMD5_000);
1305 CPPUNIT_TEST(updateMD5_001);
1306 CPPUNIT_TEST(updateMD5_002);
1307 CPPUNIT_TEST(updateMD5_000);
1308 CPPUNIT_TEST(updateSHA_000);
1309 CPPUNIT_TEST(updateSHA1_000);
1310 CPPUNIT_TEST(updateHMAC_MD5_000);
1311 CPPUNIT_TEST(updateHMAC_SHA1_000);
1312 CPPUNIT_TEST_SUITE_END();
1313 }; // class create
1314 // -----------------------------------------------------------------------------
1316 class get : public CppUnit::TestFixture
1318 public:
1319 // initialise your test code values here.
1320 void setUp()
1324 void tearDown()
1328 void get_000()
1330 rtlDigest aHandle = NULL;
1331 rtlDigestError aError = rtl_digest_get(aHandle, NULL, 0);
1332 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1334 void getMD5_000()
1336 rtlDigest aHandle = NULL;
1337 rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL, 0);
1338 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument );
1340 void getMD5_001()
1342 // test with wrong algorithm
1343 rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 );
1344 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0);
1346 sal_uInt32 nKeyLen = rtl_digest_queryLength( aHandle );
1347 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
1349 rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL, 0);
1350 CPPUNIT_ASSERT_MESSAGE("handle 2. parameter wrong", aError == rtl_Digest_E_Argument );
1352 /* rtlDigestError */ aError = rtl_digest_getMD5(aHandle, pKeyBuffer, 0);
1353 CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError == rtl_Digest_E_Algorithm );
1355 rtl_digest_destroyMD2(aHandle);
1358 void getMD5_002()
1360 rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
1361 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != 0);
1363 sal_uInt32 nKeyLen = rtl_digest_queryLength( aHandle );
1364 sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ];
1366 rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL /* pKeyBuffer */ , nKeyLen);
1367 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument );
1369 /* rtlDigestError */ aError = rtl_digest_getMD5(aHandle, pKeyBuffer, 0);
1370 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_BufferSize );
1372 rtl_digest_destroyMD5(aHandle);
1373 delete [] pKeyBuffer;
1376 // Change the following lines only, if you add, remove or rename
1377 // member functions of the current class,
1378 // because these macros are need by auto register mechanism.
1380 CPPUNIT_TEST_SUITE(get);
1381 CPPUNIT_TEST(get_000);
1382 CPPUNIT_TEST(getMD5_000);
1383 CPPUNIT_TEST(getMD5_001);
1384 CPPUNIT_TEST(getMD5_002);
1385 CPPUNIT_TEST_SUITE_END();
1386 }; // class create
1388 // -----------------------------------------------------------------------------
1389 class destroy : public CppUnit::TestFixture
1391 public:
1392 // initialise your test code values here.
1393 void setUp()
1397 void tearDown()
1401 void destroy_001()
1403 rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
1404 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle != 0);
1406 // not really testable
1407 // LLA: good will test.
1408 rtl_digest_destroy( handle );
1411 // Change the following lines only, if you add, remove or rename
1412 // member functions of the current class,
1413 // because these macros are need by auto register mechanism.
1415 CPPUNIT_TEST_SUITE(destroy);
1416 CPPUNIT_TEST(destroy_001);
1417 CPPUNIT_TEST_SUITE_END();
1418 }; // class create
1419 // -----------------------------------------------------------------------------
1421 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::create, "rtl_digest");
1422 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD2, "rtl_digest");
1423 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD5, "rtl_digest");
1424 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA, "rtl_digest");
1425 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA1, "rtl_digest");
1426 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_MD5, "rtl_digest");
1427 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_SHA1, "rtl_digest");
1429 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest");
1431 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryAlgorithm, "rtl_digest");
1432 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryLength, "rtl_digest");
1433 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::init, "rtl_digest");
1434 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::equalTests, "rtl_digest");
1436 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD2, "rtl_digest");
1437 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD5, "rtl_digest");
1438 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA, "rtl_digest");
1439 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA1, "rtl_digest");
1440 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_MD5, "rtl_digest");
1441 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_SHA1, "rtl_digest");
1442 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_PBKDF2, "rtl_digest");
1444 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::update, "rtl_digest");
1445 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::get, "rtl_digest");
1446 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest");
1447 } // namespace rtl_digest
1450 // -----------------------------------------------------------------------------
1452 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1453 // to let the user the possibility to also register some functions by hand.
1454 NOADDITIONAL;