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"
31 #include <testshl/simpleheader.hxx>
33 #include <rtl/digest.h>
34 #include <rtl/ustring.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <rtl/strbuf.hxx>
38 // sample, how to use digest
40 rtl::OUString
CreateMD5FromString( const rtl::OUString
& aMsg
)
43 // BACK: Str "ababab....0f" Hexcode String
45 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
48 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
49 sal_uInt32 nSize
= ( aMsg
.getLength() * sizeof( sal_Unicode
));
50 sal_uInt32 nMD5KeyLen
= rtl_digest_queryLength( handle
);
51 sal_uInt8
* pMD5KeyBuffer
= new sal_uInt8
[ nMD5KeyLen
];
53 rtl_digest_init( handle
, pData
, nSize
);
54 rtl_digest_update( handle
, pData
, nSize
);
55 rtl_digest_get( handle
, pMD5KeyBuffer
, nMD5KeyLen
);
56 rtl_digest_destroy( handle
);
58 // Create hex-value string from the MD5 value to keep the string size minimal
59 rtl::OUStringBuffer
aBuffer( nMD5KeyLen
* 2 + 1 );
60 for ( sal_uInt32 i
= 0; i
< nMD5KeyLen
; i
++ )
61 aBuffer
.append( (sal_Int32
)pMD5KeyBuffer
[i
], 16 );
63 delete [] pMD5KeyBuffer
;
64 return aBuffer
.makeStringAndClear();
67 return rtl::OUString();
70 // -----------------------------------------------------------------------------
74 rtl::OString sSampleString
= "This is a sample sentence, which we use to check some crypto functions in sal.";
75 rtl::OString sSampleString_MD2
= "647ee6c9d4aa5fdd374ed9d7a156acbf";
76 rtl::OString sSampleString_MD5
= "b16b903e6fc0b62ae389013ed93fe531";
77 rtl::OString sSampleString_SHA
= "eab2814429b2613301c8a077b806af3680548914";
78 rtl::OString sSampleString_SHA1
= "2bc5bdb7506a2cdc2fd27fc8b9889343012d5008";
79 rtl::OString sSampleString_HMAC_MD5
= "dd9cba48c972fba0a882baa72b079674";
80 rtl::OString sSampleString_HMAC_SHA1
= "5d7f43ce6abd1de4438d7e69e01495864490cf3e";
82 rtl::OString sSampleString_only_one_diff
= "This is a sample sentence. which we use to check some crypto functions in sal.";
84 class create
: public CppUnit::TestFixture
87 // initialise your test code values here.
98 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
99 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle
!= 0);
100 rtl_digest_destroy( handle
);
104 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
105 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", handle
!= 0);
106 rtl_digest_destroy( handle
);
110 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
111 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA", handle
!= 0);
112 rtl_digest_destroy( handle
);
116 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
117 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA1", handle
!= 0);
118 rtl_digest_destroy( handle
);
122 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
123 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_MD5", handle
!= 0);
124 rtl_digest_destroy( handle
);
128 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
129 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_SHA1", handle
!= 0);
130 rtl_digest_destroy( handle
);
135 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
136 t_print("Handle is %x\n", handle
);
137 CPPUNIT_ASSERT_MESSAGE("create with NULL", handle
== 0);
138 rtl_digest_destroy( handle
);
141 // Change the following lines only, if you add, remove or rename
142 // member functions of the current class,
143 // because these macros are need by auto register mechanism.
145 CPPUNIT_TEST_SUITE(create
);
146 CPPUNIT_TEST(create_001
);
147 CPPUNIT_TEST(create_002
);
148 CPPUNIT_TEST(create_003
);
149 CPPUNIT_TEST(create_004
);
150 CPPUNIT_TEST(create_005
);
151 CPPUNIT_TEST(create_006
);
152 CPPUNIT_TEST(create_007
);
153 CPPUNIT_TEST_SUITE_END();
159 // -----------------------------------------------------------------------------
161 class createMD5
: public CppUnit::TestFixture
164 // initialise your test code values here.
175 rtlDigest handle
= rtl_digest_createMD5();
177 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
178 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5
== aAlgo
);
180 rtl_digest_destroy( handle
);
182 CPPUNIT_TEST_SUITE(createMD5
);
183 CPPUNIT_TEST(createMD5_001
);
184 CPPUNIT_TEST_SUITE_END();
188 // -----------------------------------------------------------------------------
190 class createMD2
: public CppUnit::TestFixture
193 // initialise your test code values here.
204 rtlDigest handle
= rtl_digest_createMD2( );
206 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
207 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2
== aAlgo
);
209 rtl_digest_destroy( handle
);
211 CPPUNIT_TEST_SUITE(createMD2
);
212 CPPUNIT_TEST(createMD2_001
);
213 CPPUNIT_TEST_SUITE_END();
216 // -----------------------------------------------------------------------------
218 class createSHA
: public CppUnit::TestFixture
221 // initialise your test code values here.
232 rtlDigest handle
= rtl_digest_createSHA( );
234 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
235 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA
== aAlgo
);
237 rtl_digest_destroy( handle
);
239 CPPUNIT_TEST_SUITE(createSHA
);
240 CPPUNIT_TEST(createSHA_001
);
241 CPPUNIT_TEST_SUITE_END();
243 // -----------------------------------------------------------------------------
245 class createSHA1
: public CppUnit::TestFixture
248 // initialise your test code values here.
257 void createSHA1_001()
259 rtlDigest handle
= rtl_digest_createSHA1();
261 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
262 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1
== aAlgo
);
264 rtl_digest_destroy( handle
);
266 CPPUNIT_TEST_SUITE(createSHA1
);
267 CPPUNIT_TEST(createSHA1_001
);
268 CPPUNIT_TEST_SUITE_END();
270 // -----------------------------------------------------------------------------
272 class createHMAC_MD5
: public CppUnit::TestFixture
275 // initialise your test code values here.
284 void createHMAC_MD5_001()
286 rtlDigest handle
= rtl_digest_createHMAC_MD5();
288 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
289 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5
== aAlgo
);
291 rtl_digest_destroy( handle
);
293 CPPUNIT_TEST_SUITE(createHMAC_MD5
);
294 CPPUNIT_TEST(createHMAC_MD5_001
);
295 CPPUNIT_TEST_SUITE_END();
297 // -----------------------------------------------------------------------------
299 class createHMAC_SHA1
: public CppUnit::TestFixture
302 // initialise your test code values here.
311 void createHMAC_SHA1_001()
313 rtlDigest handle
= rtl_digest_createHMAC_SHA1();
315 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
316 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1
== aAlgo
);
318 rtl_digest_destroy( handle
);
322 CPPUNIT_TEST_SUITE(createHMAC_SHA1
);
323 CPPUNIT_TEST(createHMAC_SHA1_001
);
324 CPPUNIT_TEST_SUITE_END();
327 // -----------------------------------------------------------------------------
329 class queryAlgorithm
: public CppUnit::TestFixture
332 // initialise your test code values here.
343 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
345 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
346 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5
== aAlgo
);
348 rtl_digest_destroy( handle
);
352 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
354 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
355 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2
== aAlgo
);
357 rtl_digest_destroy( handle
);
361 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
363 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
364 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA
== aAlgo
);
366 rtl_digest_destroy( handle
);
370 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
372 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
373 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1
== aAlgo
);
375 rtl_digest_destroy( handle
);
379 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
381 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
382 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5
== aAlgo
);
384 rtl_digest_destroy( handle
);
388 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
390 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
391 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1
== aAlgo
);
393 rtl_digest_destroy( handle
);
397 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
399 rtlDigestAlgorithm aAlgo
= rtl_digest_queryAlgorithm(handle
);
400 CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmInvalid
== aAlgo
);
402 rtl_digest_destroy( handle
);
405 // Change the following lines only, if you add, remove or rename
406 // member functions of the current class,
407 // because these macros are need by auto register mechanism.
409 CPPUNIT_TEST_SUITE(queryAlgorithm
);
410 CPPUNIT_TEST( query_001
);
411 CPPUNIT_TEST( query_002
);
412 CPPUNIT_TEST( query_003
);
413 CPPUNIT_TEST( query_004
);
414 CPPUNIT_TEST( query_005
);
415 CPPUNIT_TEST( query_006
);
416 CPPUNIT_TEST( query_007
);
417 CPPUNIT_TEST_SUITE_END();
421 // -----------------------------------------------------------------------------
422 class queryLength
: public CppUnit::TestFixture
425 // initialise your test code values here.
434 void queryLength_MD5()
436 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
438 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
439 // t_print("nAlgoLength:=%d\n", nAlgoLength);
440 CPPUNIT_ASSERT_MESSAGE("query Length", RTL_DIGEST_LENGTH_MD5
== nAlgoLength
);
442 rtl_digest_destroy( handle
);
444 void queryLength_MD2()
446 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
448 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
449 // t_print("nAlgoLength:=%d\n", nAlgoLength);
450 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_MD2
== nAlgoLength
);
452 rtl_digest_destroy( handle
);
454 void queryLength_SHA()
456 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
458 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
459 // t_print("nAlgoLength:=%d\n", nAlgoLength);
460 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA
== nAlgoLength
);
462 rtl_digest_destroy( handle
);
464 void queryLength_SHA1()
466 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
468 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
469 // t_print("nAlgoLength:=%d\n", nAlgoLength);
470 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA1
== nAlgoLength
);
472 rtl_digest_destroy( handle
);
474 void queryLength_HMAC_MD5()
476 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
478 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
479 // t_print("nAlgoLength:=%d\n", nAlgoLength);
480 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_MD5
== nAlgoLength
);
482 rtl_digest_destroy( handle
);
484 void queryLength_HMAC_SHA1()
486 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
488 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
489 // t_print("nAlgoLength:=%d\n", nAlgoLength);
490 CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_SHA1
== nAlgoLength
);
492 rtl_digest_destroy( handle
);
495 void queryLength_Illegal()
497 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmInvalid
);
499 sal_uInt32 nAlgoLength
= rtl_digest_queryLength(handle
);
500 // t_print("nAlgoLength:=%d\n", nAlgoLength);
501 CPPUNIT_ASSERT_MESSAGE("query length", 0 == nAlgoLength
);
503 rtl_digest_destroy( handle
);
506 // Change the following lines only, if you add, remove or rename
507 // member functions of the current class,
508 // because these macros are need by auto register mechanism.
510 CPPUNIT_TEST_SUITE(queryLength
);
511 CPPUNIT_TEST( queryLength_MD2
);
512 CPPUNIT_TEST( queryLength_MD5
);
513 CPPUNIT_TEST( queryLength_SHA
);
514 CPPUNIT_TEST( queryLength_SHA1
);
515 CPPUNIT_TEST( queryLength_HMAC_MD5
);
516 CPPUNIT_TEST( queryLength_HMAC_SHA1
);
517 CPPUNIT_TEST( queryLength_Illegal
);
518 CPPUNIT_TEST_SUITE_END();
521 // -----------------------------------------------------------------------------
523 rtl::OString
createHex(sal_uInt8
*_pMD5KeyBuffer
, sal_uInt32 _nMD5KeyLen
)
525 // Create hex-value string from the MD5 value to keep the string size minimal
526 rtl::OStringBuffer
aBuffer( _nMD5KeyLen
* 2 + 1 );
527 for ( sal_uInt32 i
= 0; i
< _nMD5KeyLen
; i
++ )
529 sal_Int32 nValue
= (sal_Int32
)_pMD5KeyBuffer
[i
];
530 if (nValue
< 16) // maximul hex value for 1 byte
532 aBuffer
.append( sal_Int32(0), 16 /* radix */ );
534 aBuffer
.append( nValue
, 16 /* radix */ );
537 return aBuffer
.makeStringAndClear();
541 // -----------------------------------------------------------------------------
542 class init
: public CppUnit::TestFixture
545 // initialise your test code values here.
556 rtlDigest handle
= NULL
;
558 rtlDigestError aError
= rtl_digest_init(handle
, NULL
, 0);
560 CPPUNIT_ASSERT_MESSAGE("init(NULL, 0, 0)", aError
== rtl_Digest_E_Argument
);
565 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
567 rtlDigestError aError
= rtl_digest_init(handle
, NULL
, 0);
569 CPPUNIT_ASSERT_MESSAGE("init(handle, 0, 0)", aError
== rtl_Digest_E_None
);
571 rtl_digest_destroy( handle
);
574 // ------------------------------------
577 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
579 rtl::OString aMsg
= sSampleString
;
580 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
581 sal_uInt32 nSize
= ( aMsg
.getLength() );
583 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
585 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
587 rtl_digest_update( handle
, pData
, nSize
);
589 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
590 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
592 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
593 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
594 delete [] pKeyBuffer
;
596 t_print("MD2 Sum: %s\n", aSum
.getStr());
597 // LLA: how to check right values
600 rtl_digest_destroy( handle
);
605 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
607 rtl::OString aMsg
= sSampleString
;
608 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
609 sal_uInt32 nSize
= ( aMsg
.getLength() );
611 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
613 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
615 rtl_digest_update( handle
, pData
, nSize
);
617 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
618 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
620 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
621 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
622 delete [] pKeyBuffer
;
624 t_print("MD5 Sum: %s\n", aSum
.getStr());
625 // LLA: how to check right values
628 rtl_digest_destroy( handle
);
633 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA
);
635 rtl::OString aMsg
= sSampleString
;
636 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
637 sal_uInt32 nSize
= ( aMsg
.getLength() );
639 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
641 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
643 rtl_digest_update( handle
, pData
, nSize
);
645 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
646 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
648 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
649 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
650 delete [] pKeyBuffer
;
652 t_print("SHA Sum: %s\n", aSum
.getStr());
653 // LLA: how to check right values
656 rtl_digest_destroy( handle
);
660 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmSHA1
);
662 rtl::OString aMsg
= sSampleString
;
663 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
664 sal_uInt32 nSize
= ( aMsg
.getLength() );
666 rtlDigestError aError
= rtl_digest_init(handle
, pData
, nSize
);
668 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
670 rtl_digest_update( handle
, pData
, nSize
);
672 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
673 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
675 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
676 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
677 delete [] pKeyBuffer
;
679 t_print("SHA1 Sum: %s\n", aSum
.getStr());
680 // LLA: how to check right values
683 rtl_digest_destroy( handle
);
687 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5
);
689 rtl::OString aMsg
= sSampleString
;
690 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
691 sal_uInt32 nSize
= ( aMsg
.getLength() );
693 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
694 CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen
);
696 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
697 CPPUNIT_ASSERT( pKeyBuffer
);
698 memset(pKeyBuffer
, 0, nKeyLen
);
700 rtlDigestError aError
= rtl_digest_init(handle
, pKeyBuffer
, nKeyLen
);
702 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
704 rtl_digest_update( handle
, pData
, nSize
);
706 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
707 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
708 delete [] pKeyBuffer
;
710 t_print("HMAC_MD5 Sum: %s\n", aSum
.getStr());
711 // LLA: how to check right values
714 rtl_digest_destroy( handle
);
716 void init_HMAC_SHA1()
718 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1
);
720 rtl::OString aMsg
= sSampleString
;
721 const sal_uInt8
*pData
= (const sal_uInt8
*)aMsg
.getStr();
722 sal_uInt32 nSize
= ( aMsg
.getLength() );
724 sal_uInt32 nKeyLen
= rtl_digest_queryLength( handle
);
725 CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen
);
727 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
728 CPPUNIT_ASSERT( pKeyBuffer
);
729 memset(pKeyBuffer
, 0, nKeyLen
);
731 rtlDigestError aError
= rtl_digest_init(handle
, pKeyBuffer
, nKeyLen
);
733 CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError
== rtl_Digest_E_None
);
735 rtl_digest_update( handle
, pData
, nSize
);
737 rtl_digest_get( handle
, pKeyBuffer
, nKeyLen
);
738 rtl::OString aSum
= createHex(pKeyBuffer
, nKeyLen
);
739 delete [] pKeyBuffer
;
741 t_print("HMAC_SHA1 Sum: %s\n", aSum
.getStr());
742 // LLA: how to check right values
745 rtl_digest_destroy( handle
);
749 // Change the following lines only, if you add, remove or rename
750 // member functions of the current class,
751 // because these macros are need by auto register mechanism.
753 CPPUNIT_TEST_SUITE(init
);
754 CPPUNIT_TEST( init_000
);
755 CPPUNIT_TEST( init_001
);
756 CPPUNIT_TEST( init_MD2
);
757 CPPUNIT_TEST( init_MD5
);
758 CPPUNIT_TEST( init_SHA
);
759 CPPUNIT_TEST( init_SHA1
);
760 CPPUNIT_TEST( init_HMAC_MD5
);
761 CPPUNIT_TEST( init_HMAC_SHA1
);
762 CPPUNIT_TEST_SUITE_END();
765 // ------------------------------------
767 rtl::OString
getMD5Sum(rtl::OString
const& _aMsg
)
769 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
771 const sal_uInt8
*pData
= (const sal_uInt8
*)_aMsg
.getStr();
772 sal_uInt32 nSize
= ( _aMsg
.getLength() );
774 rtl_digest_init(handle
, pData
, nSize
);
775 rtl_digest_update( handle
, pData
, nSize
);
777 sal_uInt32 nMD5KeyLen
= rtl_digest_queryLength( handle
);
778 sal_uInt8
*pMD5KeyBuffer
= new sal_uInt8
[ nMD5KeyLen
];
780 rtl_digest_get( handle
, pMD5KeyBuffer
, nMD5KeyLen
);
781 rtl::OString aMD5Sum
= createHex(pMD5KeyBuffer
, nMD5KeyLen
);
782 delete [] pMD5KeyBuffer
;
784 rtl_digest_destroy( handle
);
788 // -----------------------------------------------------------------------------
790 class equalTests
: public CppUnit::TestFixture
793 // initialise your test code values here.
802 // ------------------------------------
805 rtl::OString aMsg1
= sSampleString
;
806 rtl::OString aMsg2
= sSampleString
;
808 rtl::OString aMsgMD5Sum1
= getMD5Sum(aMsg1
);
809 rtl::OString aMsgMD5Sum2
= getMD5Sum(aMsg2
);
811 CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1
.getLength() == 32 && aMsgMD5Sum2
.getLength() == 32 );
812 CPPUNIT_ASSERT_MESSAGE("source is the same, dest must be also the same", aMsgMD5Sum1
.equals(aMsgMD5Sum2
) == sal_True
);
814 // ------------------------------------
817 rtl::OString aMsg1
= sSampleString
;
818 rtl::OString aMsg2
= sSampleString_only_one_diff
;
820 rtl::OString aMsgMD5Sum1
= getMD5Sum(aMsg1
);
821 rtl::OString aMsgMD5Sum2
= getMD5Sum(aMsg2
);
823 CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1
.getLength() == 32 && aMsgMD5Sum2
.getLength() == 32 );
824 CPPUNIT_ASSERT_MESSAGE("differ only in one char", aMsgMD5Sum1
.equals(aMsgMD5Sum2
) == sal_False
);
827 // Change the following lines only, if you add, remove or rename
828 // member functions of the current class,
829 // because these macros are need by auto register mechanism.
831 CPPUNIT_TEST_SUITE(equalTests
);
832 CPPUNIT_TEST( equal_001
);
833 CPPUNIT_TEST( equal_002
);
834 CPPUNIT_TEST_SUITE_END();
838 // -----------------------------------------------------------------------------
839 class digest_MD2
: public CppUnit::TestFixture
842 // initialise your test code values here.
851 // ------------------------------------
854 rtl::OString aMsg1
= sSampleString
;
856 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_MD2
];
857 CPPUNIT_ASSERT( pBuffer
);
858 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_MD2
);
860 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
861 sal_Int32 nLen
= aMsg1
.getLength();
863 rtlDigestError aError
= rtl_digest_MD2(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_MD2
);
865 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
867 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_MD2
);
868 t_print("Decrypt MD2: %s\n", aStr
.getStr());
869 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_MD2
) );
874 // Change the following lines only, if you add, remove or rename
875 // member functions of the current class,
876 // because these macros are need by auto register mechanism.
878 CPPUNIT_TEST_SUITE(digest_MD2
);
879 CPPUNIT_TEST( MD2_001
);
880 CPPUNIT_TEST_SUITE_END();
882 // -----------------------------------------------------------------------------
883 class digest_MD5
: public CppUnit::TestFixture
886 // initialise your test code values here.
894 // ------------------------------------
897 rtl::OString aMsg1
= sSampleString
;
899 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_MD5
];
900 CPPUNIT_ASSERT( pBuffer
);
901 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_MD5
);
903 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
904 sal_Int32 nLen
= aMsg1
.getLength();
906 rtlDigestError aError
= rtl_digest_MD5(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_MD5
);
908 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
910 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_MD5
);
911 t_print("Decrypt MD5: %s\n", aStr
.getStr());
912 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_MD5
) );
917 // Change the following lines only, if you add, remove or rename
918 // member functions of the current class,
919 // because these macros are need by auto register mechanism.
921 CPPUNIT_TEST_SUITE(digest_MD5
);
922 CPPUNIT_TEST( MD5_001
);
923 CPPUNIT_TEST_SUITE_END();
926 // -----------------------------------------------------------------------------
927 class digest_SHA
: public CppUnit::TestFixture
930 // initialise your test code values here.
939 // ------------------------------------
942 rtl::OString aMsg1
= sSampleString
;
944 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_SHA
];
945 CPPUNIT_ASSERT( pBuffer
);
946 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_SHA
);
948 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
949 sal_Int32 nLen
= aMsg1
.getLength();
951 rtlDigestError aError
= rtl_digest_SHA(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_SHA
);
953 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
955 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_SHA
);
956 t_print("Decrypt SHA: %s\n", aStr
.getStr());
957 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_SHA
) );
962 // Change the following lines only, if you add, remove or rename
963 // member functions of the current class,
964 // because these macros are need by auto register mechanism.
966 CPPUNIT_TEST_SUITE(digest_SHA
);
967 CPPUNIT_TEST( SHA_001
);
968 CPPUNIT_TEST_SUITE_END();
971 // -----------------------------------------------------------------------------
972 class digest_SHA1
: public CppUnit::TestFixture
975 // initialise your test code values here.
984 // ------------------------------------
987 rtl::OString aMsg1
= sSampleString
;
989 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_SHA1
];
990 CPPUNIT_ASSERT( pBuffer
);
991 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_SHA1
);
993 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
994 sal_Int32 nLen
= aMsg1
.getLength();
996 rtlDigestError aError
= rtl_digest_SHA1(pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_SHA1
);
998 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1000 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_SHA1
);
1001 t_print("Decrypt SHA1: %s\n", aStr
.getStr());
1002 CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_SHA1
) );
1006 // Change the following lines only, if you add, remove or rename
1007 // member functions of the current class,
1008 // because these macros are need by auto register mechanism.
1010 CPPUNIT_TEST_SUITE(digest_SHA1
);
1011 CPPUNIT_TEST( SHA1_001
);
1012 CPPUNIT_TEST_SUITE_END();
1014 // -----------------------------------------------------------------------------
1015 class digest_HMAC_MD5
: public CppUnit::TestFixture
1018 // initialise your test code values here.
1027 // ------------------------------------
1030 rtl::OString aMsg1
= sSampleString
;
1032 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_MD5
];
1033 CPPUNIT_ASSERT( pKeyBuffer
);
1034 memset(pKeyBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_MD5
);
1036 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_MD5
];
1037 CPPUNIT_ASSERT( pBuffer
);
1038 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_MD5
);
1040 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
1041 sal_Int32 nLen
= aMsg1
.getLength();
1043 rtlDigestError aError
= rtl_digest_HMAC_MD5(pKeyBuffer
, RTL_DIGEST_LENGTH_HMAC_MD5
, pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_HMAC_MD5
);
1045 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1047 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_HMAC_MD5
);
1048 t_print("Decrypt HMAC_MD5: %s\n", aStr
.getStr());
1049 CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_HMAC_MD5
) );
1053 // Change the following lines only, if you add, remove or rename
1054 // member functions of the current class,
1055 // because these macros are need by auto register mechanism.
1057 CPPUNIT_TEST_SUITE(digest_HMAC_MD5
);
1058 CPPUNIT_TEST( HMAC_MD5_001
);
1059 CPPUNIT_TEST_SUITE_END();
1061 // -----------------------------------------------------------------------------
1062 class digest_HMAC_SHA1
: public CppUnit::TestFixture
1065 // initialise your test code values here.
1074 // ------------------------------------
1075 void HMAC_SHA1_001()
1077 rtl::OString aMsg1
= sSampleString
;
1079 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_SHA1
];
1080 CPPUNIT_ASSERT( pKeyBuffer
);
1081 memset(pKeyBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1083 sal_uInt8
*pBuffer
= new sal_uInt8
[ RTL_DIGEST_LENGTH_HMAC_SHA1
];
1084 CPPUNIT_ASSERT( pBuffer
);
1085 memset(pBuffer
, 0, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1087 sal_uInt8
*pMsg1
= (sal_uInt8
*)aMsg1
.getStr();
1088 sal_Int32 nLen
= aMsg1
.getLength();
1090 rtlDigestError aError
= rtl_digest_HMAC_SHA1(pKeyBuffer
, RTL_DIGEST_LENGTH_HMAC_SHA1
, pMsg1
, nLen
, pBuffer
, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1092 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1094 rtl::OString aStr
= createHex(pBuffer
, RTL_DIGEST_LENGTH_HMAC_SHA1
);
1095 t_print("Decrypt HMAC_SHA1: %s\n", aStr
.getStr());
1096 CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr
.equals(sSampleString_HMAC_SHA1
) );
1101 // Change the following lines only, if you add, remove or rename
1102 // member functions of the current class,
1103 // because these macros are need by auto register mechanism.
1105 CPPUNIT_TEST_SUITE(digest_HMAC_SHA1
);
1106 CPPUNIT_TEST( HMAC_SHA1_001
);
1107 CPPUNIT_TEST_SUITE_END();
1109 // -----------------------------------------------------------------------------
1110 class digest_PBKDF2
: public CppUnit::TestFixture
1113 // initialise your test code values here.
1122 // ------------------------------------
1123 rtl::OString
/* key */ run_check_PBKDF2(rtl::OString
const& _sPassword
, bool _bClearSalt
, sal_uInt32 _nCount
)
1125 sal_uInt32 nKeyLen
= RTL_DIGEST_LENGTH_HMAC_SHA1
;
1126 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
1127 CPPUNIT_ASSERT( pKeyBuffer
);
1128 memset(pKeyBuffer
, 0, nKeyLen
);
1130 sal_uInt8
*pPassword
= (sal_uInt8
*)_sPassword
.getStr();
1131 sal_Int32 nPasswordLen
= _sPassword
.getLength();
1133 sal_uInt32 nSaltDataLen
= RTL_DIGEST_LENGTH_HMAC_SHA1
;
1134 sal_uInt8
*pSaltData
= new sal_uInt8
[ nSaltDataLen
];
1135 CPPUNIT_ASSERT( pSaltData
);
1136 memset(pSaltData
, 0, nSaltDataLen
);
1140 // wilful contamination
1144 rtlDigestError aError
= rtl_digest_PBKDF2(pKeyBuffer
, nKeyLen
, pPassword
, nPasswordLen
, pSaltData
, nSaltDataLen
, _nCount
);
1146 CPPUNIT_ASSERT(aError
== rtl_Digest_E_None
);
1148 rtl::OString aKey
= createHex(pKeyBuffer
, nKeyLen
);
1149 t_print("Key: %s\n", aKey
.getStr());
1151 // rtl::OString sSalt = createHex(pSaltData, nSaltDataLen);
1152 // t_print("Salt: %s\n", sSalt.getStr());
1154 // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) );
1156 delete [] pSaltData
;
1157 delete [] pKeyBuffer
;
1163 rtl::OString aPassword
= "Password";
1166 run_check_PBKDF2(aPassword
, false, 1);
1167 run_check_PBKDF2(aPassword
, false, 2);
1168 run_check_PBKDF2(aPassword
, true, 1);
1169 run_check_PBKDF2(aPassword
, true, 2);
1170 run_check_PBKDF2(aPassword
, false, 3);
1171 run_check_PBKDF2(aPassword
, false, 4);
1172 run_check_PBKDF2(aPassword
, true, 3);
1173 run_check_PBKDF2(aPassword
, true, 4);
1175 // Change the following lines only, if you add, remove or rename
1176 // member functions of the current class,
1177 // because these macros are need by auto register mechanism.
1179 CPPUNIT_TEST_SUITE(digest_PBKDF2
);
1180 CPPUNIT_TEST( PBKDF2_001
);
1181 CPPUNIT_TEST_SUITE_END();
1183 // -----------------------------------------------------------------------------
1185 class update
: public CppUnit::TestFixture
1188 // initialise your test code values here.
1199 rtlDigest aHandle
= NULL
;
1200 rtlDigestError aError
= rtl_digest_update(aHandle
, NULL
, 0);
1201 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1204 void updateMD2_000()
1206 rtlDigest aHandle
= NULL
;
1207 rtlDigestError aError
= rtl_digest_updateMD2(aHandle
, NULL
, 0);
1208 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1211 void updateMD2_001()
1213 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
1214 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= 0);
1216 rtl::OString aMsg
= sSampleString
;
1217 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
1219 rtlDigestError aError
= rtl_digest_updateMD2(aHandle
, NULL
, 0);
1220 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError
== rtl_Digest_E_Argument
);
1222 /* rtlDigestError */ aError
= rtl_digest_updateMD2(aHandle
, pData
, 0);
1223 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError
== rtl_Digest_E_None
);
1225 rtl_digest_destroyMD2(aHandle
);
1227 void updateMD5_000()
1229 rtlDigest aHandle
= NULL
;
1230 rtlDigestError aError
= rtl_digest_updateMD5(aHandle
, NULL
, 0);
1231 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1234 void updateMD5_001()
1236 // use wrong Algorithm!!! This is volitional!
1237 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
1238 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= 0);
1240 rtl::OString aMsg
= sSampleString
;
1241 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
1242 sal_uInt32 nSize
= ( aMsg
.getLength() );
1244 rtlDigestError aError
= rtl_digest_updateMD5(aHandle
, pData
, nSize
);
1245 CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError
== rtl_Digest_E_Algorithm
);
1247 rtl_digest_destroyMD5(aHandle
);
1250 void updateMD5_002()
1252 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
1253 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle
!= 0);
1255 rtl::OString aMsg
= sSampleString
;
1256 const sal_uInt8
* pData
= (const sal_uInt8
*)aMsg
.getStr();
1258 rtlDigestError aError
= rtl_digest_updateMD5(aHandle
, NULL
, 0);
1259 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError
== rtl_Digest_E_Argument
);
1261 /* rtlDigestError */ aError
= rtl_digest_updateMD5(aHandle
, pData
, 0);
1262 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError
== rtl_Digest_E_None
);
1264 rtl_digest_destroyMD5(aHandle
);
1267 void updateSHA_000()
1269 rtlDigest aHandle
= NULL
;
1270 rtlDigestError aError
= rtl_digest_updateSHA(aHandle
, NULL
, 0);
1271 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1274 void updateSHA1_000()
1276 rtlDigest aHandle
= NULL
;
1277 rtlDigestError aError
= rtl_digest_updateSHA1(aHandle
, NULL
, 0);
1278 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1281 void updateHMAC_MD5_000()
1283 rtlDigest aHandle
= NULL
;
1284 rtlDigestError aError
= rtl_digest_updateHMAC_MD5(aHandle
, NULL
, 0);
1285 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1288 void updateHMAC_SHA1_000()
1290 rtlDigest aHandle
= NULL
;
1291 rtlDigestError aError
= rtl_digest_updateHMAC_SHA1(aHandle
, NULL
, 0);
1292 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1295 // Change the following lines only, if you add, remove or rename
1296 // member functions of the current class,
1297 // because these macros are need by auto register mechanism.
1299 CPPUNIT_TEST_SUITE(update
);
1300 CPPUNIT_TEST(update_000
);
1301 CPPUNIT_TEST(updateMD5_000
);
1302 CPPUNIT_TEST(updateMD5_001
);
1303 CPPUNIT_TEST(updateMD5_002
);
1304 CPPUNIT_TEST(updateMD5_000
);
1305 CPPUNIT_TEST(updateSHA_000
);
1306 CPPUNIT_TEST(updateSHA1_000
);
1307 CPPUNIT_TEST(updateHMAC_MD5_000
);
1308 CPPUNIT_TEST(updateHMAC_SHA1_000
);
1309 CPPUNIT_TEST_SUITE_END();
1311 // -----------------------------------------------------------------------------
1313 class get
: public CppUnit::TestFixture
1316 // initialise your test code values here.
1327 rtlDigest aHandle
= NULL
;
1328 rtlDigestError aError
= rtl_digest_get(aHandle
, NULL
, 0);
1329 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1333 rtlDigest aHandle
= NULL
;
1334 rtlDigestError aError
= rtl_digest_getMD5(aHandle
, NULL
, 0);
1335 CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError
== rtl_Digest_E_Argument
);
1339 // test with wrong algorithm
1340 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD2
);
1341 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle
!= 0);
1343 sal_uInt32 nKeyLen
= rtl_digest_queryLength( aHandle
);
1344 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
1346 rtlDigestError aError
= rtl_digest_getMD5(aHandle
, NULL
, 0);
1347 CPPUNIT_ASSERT_MESSAGE("handle 2. parameter wrong", aError
== rtl_Digest_E_Argument
);
1349 /* rtlDigestError */ aError
= rtl_digest_getMD5(aHandle
, pKeyBuffer
, 0);
1350 CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError
== rtl_Digest_E_Algorithm
);
1352 rtl_digest_destroyMD2(aHandle
);
1357 rtlDigest aHandle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
1358 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle
!= 0);
1360 sal_uInt32 nKeyLen
= rtl_digest_queryLength( aHandle
);
1361 sal_uInt8
*pKeyBuffer
= new sal_uInt8
[ nKeyLen
];
1363 rtlDigestError aError
= rtl_digest_getMD5(aHandle
, NULL
/* pKeyBuffer */ , nKeyLen
);
1364 CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError
== rtl_Digest_E_Argument
);
1366 /* rtlDigestError */ aError
= rtl_digest_getMD5(aHandle
, pKeyBuffer
, 0);
1367 CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError
== rtl_Digest_E_BufferSize
);
1369 rtl_digest_destroyMD5(aHandle
);
1370 delete [] pKeyBuffer
;
1373 // Change the following lines only, if you add, remove or rename
1374 // member functions of the current class,
1375 // because these macros are need by auto register mechanism.
1377 CPPUNIT_TEST_SUITE(get
);
1378 CPPUNIT_TEST(get_000
);
1379 CPPUNIT_TEST(getMD5_000
);
1380 CPPUNIT_TEST(getMD5_001
);
1381 CPPUNIT_TEST(getMD5_002
);
1382 CPPUNIT_TEST_SUITE_END();
1385 // -----------------------------------------------------------------------------
1386 class destroy
: public CppUnit::TestFixture
1389 // initialise your test code values here.
1400 rtlDigest handle
= rtl_digest_create( rtl_Digest_AlgorithmMD5
);
1401 CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle
!= 0);
1403 // not really testable
1404 // LLA: good will test.
1405 rtl_digest_destroy( handle
);
1408 // Change the following lines only, if you add, remove or rename
1409 // member functions of the current class,
1410 // because these macros are need by auto register mechanism.
1412 CPPUNIT_TEST_SUITE(destroy
);
1413 CPPUNIT_TEST(destroy_001
);
1414 CPPUNIT_TEST_SUITE_END();
1416 // -----------------------------------------------------------------------------
1418 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::create
, "rtl_digest");
1419 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD2
, "rtl_digest");
1420 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD5
, "rtl_digest");
1421 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA
, "rtl_digest");
1422 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA1
, "rtl_digest");
1423 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_MD5
, "rtl_digest");
1424 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_SHA1
, "rtl_digest");
1426 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy
, "rtl_digest");
1428 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryAlgorithm
, "rtl_digest");
1429 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryLength
, "rtl_digest");
1430 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::init
, "rtl_digest");
1431 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::equalTests
, "rtl_digest");
1433 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD2
, "rtl_digest");
1434 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD5
, "rtl_digest");
1435 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA
, "rtl_digest");
1436 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA1
, "rtl_digest");
1437 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_MD5
, "rtl_digest");
1438 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_SHA1
, "rtl_digest");
1439 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_PBKDF2
, "rtl_digest");
1441 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::update
, "rtl_digest");
1442 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::get
, "rtl_digest");
1443 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy
, "rtl_digest");
1444 } // namespace rtl_digest
1447 // -----------------------------------------------------------------------------
1449 // this macro creates an empty function, which will called by the RegisterAllFunctions()
1450 // to let the user the possibility to also register some functions by hand.