1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 30*cdf0e10cSrcweir #include "precompiled_sal.hxx" 31*cdf0e10cSrcweir #include <testshl/simpleheader.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <rtl/digest.h> 34*cdf0e10cSrcweir #include <rtl/ustring.hxx> 35*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 36*cdf0e10cSrcweir #include <rtl/strbuf.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir // sample, how to use digest 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir rtl::OUString CreateMD5FromString( const rtl::OUString& aMsg ) 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir // PRE: aStr "file" 43*cdf0e10cSrcweir // BACK: Str "ababab....0f" Hexcode String 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 46*cdf0e10cSrcweir if ( handle > 0 ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); 49*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() * sizeof( sal_Unicode )); 50*cdf0e10cSrcweir sal_uInt32 nMD5KeyLen = rtl_digest_queryLength( handle ); 51*cdf0e10cSrcweir sal_uInt8* pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ]; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir rtl_digest_init( handle, pData, nSize ); 54*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 55*cdf0e10cSrcweir rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen ); 56*cdf0e10cSrcweir rtl_digest_destroy( handle ); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // Create hex-value string from the MD5 value to keep the string size minimal 59*cdf0e10cSrcweir rtl::OUStringBuffer aBuffer( nMD5KeyLen * 2 + 1 ); 60*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nMD5KeyLen; i++ ) 61*cdf0e10cSrcweir aBuffer.append( (sal_Int32)pMD5KeyBuffer[i], 16 ); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir delete [] pMD5KeyBuffer; 64*cdf0e10cSrcweir return aBuffer.makeStringAndClear(); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir return rtl::OUString(); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 71*cdf0e10cSrcweir namespace rtl_digest 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir rtl::OString sSampleString = "This is a sample sentence, which we use to check some crypto functions in sal."; 75*cdf0e10cSrcweir rtl::OString sSampleString_MD2 = "647ee6c9d4aa5fdd374ed9d7a156acbf"; 76*cdf0e10cSrcweir rtl::OString sSampleString_MD5 = "b16b903e6fc0b62ae389013ed93fe531"; 77*cdf0e10cSrcweir rtl::OString sSampleString_SHA = "eab2814429b2613301c8a077b806af3680548914"; 78*cdf0e10cSrcweir rtl::OString sSampleString_SHA1 = "2bc5bdb7506a2cdc2fd27fc8b9889343012d5008"; 79*cdf0e10cSrcweir rtl::OString sSampleString_HMAC_MD5 = "dd9cba48c972fba0a882baa72b079674"; 80*cdf0e10cSrcweir rtl::OString sSampleString_HMAC_SHA1 = "5d7f43ce6abd1de4438d7e69e01495864490cf3e"; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir rtl::OString sSampleString_only_one_diff = "This is a sample sentence. which we use to check some crypto functions in sal."; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir class create : public CppUnit::TestFixture 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir public: 87*cdf0e10cSrcweir // initialise your test code values here. 88*cdf0e10cSrcweir void setUp() 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir void tearDown() 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir void create_001() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 99*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle != 0); 100*cdf0e10cSrcweir rtl_digest_destroy( handle ); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir void create_002() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 105*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", handle != 0); 106*cdf0e10cSrcweir rtl_digest_destroy( handle ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir void create_003() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); 111*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA", handle != 0); 112*cdf0e10cSrcweir rtl_digest_destroy( handle ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir void create_004() 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); 117*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmSHA1", handle != 0); 118*cdf0e10cSrcweir rtl_digest_destroy( handle ); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir void create_005() 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); 123*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_MD5", handle != 0); 124*cdf0e10cSrcweir rtl_digest_destroy( handle ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir void create_006() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); 129*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmHMAC_SHA1", handle != 0); 130*cdf0e10cSrcweir rtl_digest_destroy( handle ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir void create_007() 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); 136*cdf0e10cSrcweir t_print("Handle is %x\n", handle); 137*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with NULL", handle == 0); 138*cdf0e10cSrcweir rtl_digest_destroy( handle ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 142*cdf0e10cSrcweir // member functions of the current class, 143*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(create); 146*cdf0e10cSrcweir CPPUNIT_TEST(create_001); 147*cdf0e10cSrcweir CPPUNIT_TEST(create_002); 148*cdf0e10cSrcweir CPPUNIT_TEST(create_003); 149*cdf0e10cSrcweir CPPUNIT_TEST(create_004); 150*cdf0e10cSrcweir CPPUNIT_TEST(create_005); 151*cdf0e10cSrcweir CPPUNIT_TEST(create_006); 152*cdf0e10cSrcweir CPPUNIT_TEST(create_007); 153*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 154*cdf0e10cSrcweir }; // class create 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir class createMD5 : public CppUnit::TestFixture 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir public: 164*cdf0e10cSrcweir // initialise your test code values here. 165*cdf0e10cSrcweir void setUp() 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir void tearDown() 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir void createMD5_001() 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir rtlDigest handle = rtl_digest_createMD5(); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 178*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5 == aAlgo); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir rtl_digest_destroy( handle ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(createMD5); 183*cdf0e10cSrcweir CPPUNIT_TEST(createMD5_001); 184*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 185*cdf0e10cSrcweir }; // class create 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir class createMD2 : public CppUnit::TestFixture 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir public: 193*cdf0e10cSrcweir // initialise your test code values here. 194*cdf0e10cSrcweir void setUp() 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void tearDown() 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir void createMD2_001() 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir rtlDigest handle = rtl_digest_createMD2( ); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 207*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2 == aAlgo); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir rtl_digest_destroy( handle ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(createMD2); 212*cdf0e10cSrcweir CPPUNIT_TEST(createMD2_001); 213*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 214*cdf0e10cSrcweir }; // class create 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir class createSHA : public CppUnit::TestFixture 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir public: 221*cdf0e10cSrcweir // initialise your test code values here. 222*cdf0e10cSrcweir void setUp() 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir void tearDown() 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir void createSHA_001() 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir rtlDigest handle = rtl_digest_createSHA( ); 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 235*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA == aAlgo); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir rtl_digest_destroy( handle ); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(createSHA); 240*cdf0e10cSrcweir CPPUNIT_TEST(createSHA_001); 241*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 242*cdf0e10cSrcweir }; // class create 243*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir class createSHA1 : public CppUnit::TestFixture 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir public: 248*cdf0e10cSrcweir // initialise your test code values here. 249*cdf0e10cSrcweir void setUp() 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir void tearDown() 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void createSHA1_001() 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir rtlDigest handle = rtl_digest_createSHA1(); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 262*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1 == aAlgo); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir rtl_digest_destroy( handle ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(createSHA1); 267*cdf0e10cSrcweir CPPUNIT_TEST(createSHA1_001); 268*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 269*cdf0e10cSrcweir }; // class create 270*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir class createHMAC_MD5 : public CppUnit::TestFixture 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir public: 275*cdf0e10cSrcweir // initialise your test code values here. 276*cdf0e10cSrcweir void setUp() 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir void tearDown() 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir void createHMAC_MD5_001() 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir rtlDigest handle = rtl_digest_createHMAC_MD5(); 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 289*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5 == aAlgo); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir rtl_digest_destroy( handle ); 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(createHMAC_MD5); 294*cdf0e10cSrcweir CPPUNIT_TEST(createHMAC_MD5_001); 295*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 296*cdf0e10cSrcweir }; // class create 297*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir class createHMAC_SHA1 : public CppUnit::TestFixture 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir public: 302*cdf0e10cSrcweir // initialise your test code values here. 303*cdf0e10cSrcweir void setUp() 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir void tearDown() 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir void createHMAC_SHA1_001() 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir rtlDigest handle = rtl_digest_createHMAC_SHA1(); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 316*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1 == aAlgo); 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir rtl_digest_destroy( handle ); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(createHMAC_SHA1); 323*cdf0e10cSrcweir CPPUNIT_TEST(createHMAC_SHA1_001); 324*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 325*cdf0e10cSrcweir }; // class create 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir class queryAlgorithm : public CppUnit::TestFixture 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir public: 332*cdf0e10cSrcweir // initialise your test code values here. 333*cdf0e10cSrcweir void setUp() 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir void tearDown() 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir void query_001() 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 346*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD5 == aAlgo); 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir rtl_digest_destroy( handle ); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir void query_002() 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 355*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmMD2 == aAlgo); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir rtl_digest_destroy( handle ); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir void query_003() 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 364*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA == aAlgo); 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir rtl_digest_destroy( handle ); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir void query_004() 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 373*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmSHA1 == aAlgo); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir rtl_digest_destroy( handle ); 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir void query_005() 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 382*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_MD5 == aAlgo); 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir rtl_digest_destroy( handle ); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir void query_006() 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 391*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmHMAC_SHA1 == aAlgo); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir rtl_digest_destroy( handle ); 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir void query_007() 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir rtlDigestAlgorithm aAlgo = rtl_digest_queryAlgorithm(handle); 400*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query handle", rtl_Digest_AlgorithmInvalid == aAlgo); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir rtl_digest_destroy( handle ); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 406*cdf0e10cSrcweir // member functions of the current class, 407*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(queryAlgorithm); 410*cdf0e10cSrcweir CPPUNIT_TEST( query_001 ); 411*cdf0e10cSrcweir CPPUNIT_TEST( query_002 ); 412*cdf0e10cSrcweir CPPUNIT_TEST( query_003 ); 413*cdf0e10cSrcweir CPPUNIT_TEST( query_004 ); 414*cdf0e10cSrcweir CPPUNIT_TEST( query_005 ); 415*cdf0e10cSrcweir CPPUNIT_TEST( query_006 ); 416*cdf0e10cSrcweir CPPUNIT_TEST( query_007 ); 417*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 418*cdf0e10cSrcweir }; // class create 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 422*cdf0e10cSrcweir class queryLength : public CppUnit::TestFixture 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir public: 425*cdf0e10cSrcweir // initialise your test code values here. 426*cdf0e10cSrcweir void setUp() 427*cdf0e10cSrcweir { 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir void tearDown() 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir void queryLength_MD5() 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 439*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 440*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query Length", RTL_DIGEST_LENGTH_MD5 == nAlgoLength); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir rtl_digest_destroy( handle ); 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir void queryLength_MD2() 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 449*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 450*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_MD2 == nAlgoLength); 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir rtl_digest_destroy( handle ); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir void queryLength_SHA() 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 459*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 460*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA == nAlgoLength); 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir rtl_digest_destroy( handle ); 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir void queryLength_SHA1() 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 469*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 470*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA1 == nAlgoLength); 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir rtl_digest_destroy( handle ); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir void queryLength_HMAC_MD5() 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 479*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 480*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_MD5 == nAlgoLength); 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir rtl_digest_destroy( handle ); 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir void queryLength_HMAC_SHA1() 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 489*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 490*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_SHA1 == nAlgoLength); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir rtl_digest_destroy( handle ); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir void queryLength_Illegal() 496*cdf0e10cSrcweir { 497*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); 500*cdf0e10cSrcweir // t_print("nAlgoLength:=%d\n", nAlgoLength); 501*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("query length", 0 == nAlgoLength); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir rtl_digest_destroy( handle ); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 507*cdf0e10cSrcweir // member functions of the current class, 508*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(queryLength); 511*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_MD2 ); 512*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_MD5 ); 513*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_SHA ); 514*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_SHA1 ); 515*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_HMAC_MD5 ); 516*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_HMAC_SHA1 ); 517*cdf0e10cSrcweir CPPUNIT_TEST( queryLength_Illegal ); 518*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 519*cdf0e10cSrcweir }; // class create 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir rtl::OString createHex(sal_uInt8 *_pMD5KeyBuffer, sal_uInt32 _nMD5KeyLen) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir // Create hex-value string from the MD5 value to keep the string size minimal 526*cdf0e10cSrcweir rtl::OStringBuffer aBuffer( _nMD5KeyLen * 2 + 1 ); 527*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < _nMD5KeyLen; i++ ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir sal_Int32 nValue = (sal_Int32)_pMD5KeyBuffer[i]; 530*cdf0e10cSrcweir if (nValue < 16) // maximul hex value for 1 byte 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir aBuffer.append( sal_Int32(0), 16 /* radix */ ); 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir aBuffer.append( nValue, 16 /* radix */ ); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir return aBuffer.makeStringAndClear(); 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 542*cdf0e10cSrcweir class init : public CppUnit::TestFixture 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir public: 545*cdf0e10cSrcweir // initialise your test code values here. 546*cdf0e10cSrcweir void setUp() 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir void tearDown() 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir void init_000() 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir rtlDigest handle = NULL; 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, NULL, 0); 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(NULL, 0, 0)", aError == rtl_Digest_E_Argument); 561*cdf0e10cSrcweir } 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir void init_001() 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, NULL, 0); 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, 0, 0)", aError == rtl_Digest_E_None); 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir rtl_digest_destroy( handle ); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir // ------------------------------------ 575*cdf0e10cSrcweir void init_MD2() 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 580*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); 581*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, pData, nSize); 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); 590*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir rtl_digest_get( handle, pKeyBuffer, nKeyLen ); 593*cdf0e10cSrcweir rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); 594*cdf0e10cSrcweir delete [] pKeyBuffer; 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir t_print("MD2 Sum: %s\n", aSum.getStr()); 597*cdf0e10cSrcweir // LLA: how to check right values 598*cdf0e10cSrcweir // samples? 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir rtl_digest_destroy( handle ); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir void init_MD5() 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 608*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); 609*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, pData, nSize); 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); 618*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir rtl_digest_get( handle, pKeyBuffer, nKeyLen ); 621*cdf0e10cSrcweir rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); 622*cdf0e10cSrcweir delete [] pKeyBuffer; 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir t_print("MD5 Sum: %s\n", aSum.getStr()); 625*cdf0e10cSrcweir // LLA: how to check right values 626*cdf0e10cSrcweir // samples? 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir rtl_digest_destroy( handle ); 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir void init_SHA() 632*cdf0e10cSrcweir { 633*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 636*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); 637*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, pData, nSize); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); 642*cdf0e10cSrcweir 643*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); 646*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir rtl_digest_get( handle, pKeyBuffer, nKeyLen ); 649*cdf0e10cSrcweir rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); 650*cdf0e10cSrcweir delete [] pKeyBuffer; 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir t_print("SHA Sum: %s\n", aSum.getStr()); 653*cdf0e10cSrcweir // LLA: how to check right values 654*cdf0e10cSrcweir // samples? 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir rtl_digest_destroy( handle ); 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir void init_SHA1() 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 663*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); 664*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, pData, nSize); 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); 673*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir rtl_digest_get( handle, pKeyBuffer, nKeyLen ); 676*cdf0e10cSrcweir rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); 677*cdf0e10cSrcweir delete [] pKeyBuffer; 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir t_print("SHA1 Sum: %s\n", aSum.getStr()); 680*cdf0e10cSrcweir // LLA: how to check right values 681*cdf0e10cSrcweir // samples? 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir rtl_digest_destroy( handle ); 684*cdf0e10cSrcweir } 685*cdf0e10cSrcweir void init_HMAC_MD5() 686*cdf0e10cSrcweir { 687*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 690*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); 691*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); 694*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen ); 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 697*cdf0e10cSrcweir CPPUNIT_ASSERT( pKeyBuffer ); 698*cdf0e10cSrcweir memset(pKeyBuffer, 0, nKeyLen); 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, pKeyBuffer, nKeyLen ); 701*cdf0e10cSrcweir 702*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir rtl_digest_get( handle, pKeyBuffer, nKeyLen ); 707*cdf0e10cSrcweir rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); 708*cdf0e10cSrcweir delete [] pKeyBuffer; 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir t_print("HMAC_MD5 Sum: %s\n", aSum.getStr()); 711*cdf0e10cSrcweir // LLA: how to check right values 712*cdf0e10cSrcweir // samples? 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir rtl_digest_destroy( handle ); 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir void init_HMAC_SHA1() 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 721*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)aMsg.getStr(); 722*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( handle ); 725*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( "Keylen must be greater 0", nKeyLen ); 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 728*cdf0e10cSrcweir CPPUNIT_ASSERT( pKeyBuffer ); 729*cdf0e10cSrcweir memset(pKeyBuffer, 0, nKeyLen); 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_init(handle, pKeyBuffer, nKeyLen ); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("init(handle, pData, nSize)", aError == rtl_Digest_E_None); 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 736*cdf0e10cSrcweir 737*cdf0e10cSrcweir rtl_digest_get( handle, pKeyBuffer, nKeyLen ); 738*cdf0e10cSrcweir rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); 739*cdf0e10cSrcweir delete [] pKeyBuffer; 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir t_print("HMAC_SHA1 Sum: %s\n", aSum.getStr()); 742*cdf0e10cSrcweir // LLA: how to check right values 743*cdf0e10cSrcweir // samples? 744*cdf0e10cSrcweir 745*cdf0e10cSrcweir rtl_digest_destroy( handle ); 746*cdf0e10cSrcweir } 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 750*cdf0e10cSrcweir // member functions of the current class, 751*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(init); 754*cdf0e10cSrcweir CPPUNIT_TEST( init_000 ); 755*cdf0e10cSrcweir CPPUNIT_TEST( init_001 ); 756*cdf0e10cSrcweir CPPUNIT_TEST( init_MD2 ); 757*cdf0e10cSrcweir CPPUNIT_TEST( init_MD5 ); 758*cdf0e10cSrcweir CPPUNIT_TEST( init_SHA ); 759*cdf0e10cSrcweir CPPUNIT_TEST( init_SHA1 ); 760*cdf0e10cSrcweir CPPUNIT_TEST( init_HMAC_MD5 ); 761*cdf0e10cSrcweir CPPUNIT_TEST( init_HMAC_SHA1 ); 762*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 763*cdf0e10cSrcweir }; // class init 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir // ------------------------------------ 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir rtl::OString getMD5Sum(rtl::OString const& _aMsg ) 768*cdf0e10cSrcweir { 769*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir const sal_uInt8 *pData = (const sal_uInt8*)_aMsg.getStr(); 772*cdf0e10cSrcweir sal_uInt32 nSize = ( _aMsg.getLength() ); 773*cdf0e10cSrcweir 774*cdf0e10cSrcweir rtl_digest_init(handle, pData, nSize); 775*cdf0e10cSrcweir rtl_digest_update( handle, pData, nSize ); 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir sal_uInt32 nMD5KeyLen = rtl_digest_queryLength( handle ); 778*cdf0e10cSrcweir sal_uInt8 *pMD5KeyBuffer = new sal_uInt8[ nMD5KeyLen ]; 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir rtl_digest_get( handle, pMD5KeyBuffer, nMD5KeyLen ); 781*cdf0e10cSrcweir rtl::OString aMD5Sum = createHex(pMD5KeyBuffer, nMD5KeyLen); 782*cdf0e10cSrcweir delete [] pMD5KeyBuffer; 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir rtl_digest_destroy( handle ); 785*cdf0e10cSrcweir return aMD5Sum; 786*cdf0e10cSrcweir } 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 789*cdf0e10cSrcweir 790*cdf0e10cSrcweir class equalTests : public CppUnit::TestFixture 791*cdf0e10cSrcweir { 792*cdf0e10cSrcweir public: 793*cdf0e10cSrcweir // initialise your test code values here. 794*cdf0e10cSrcweir void setUp() 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir } 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir void tearDown() 799*cdf0e10cSrcweir { 800*cdf0e10cSrcweir } 801*cdf0e10cSrcweir 802*cdf0e10cSrcweir // ------------------------------------ 803*cdf0e10cSrcweir void equal_001() 804*cdf0e10cSrcweir { 805*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 806*cdf0e10cSrcweir rtl::OString aMsg2 = sSampleString; 807*cdf0e10cSrcweir 808*cdf0e10cSrcweir rtl::OString aMsgMD5Sum1 = getMD5Sum(aMsg1); 809*cdf0e10cSrcweir rtl::OString aMsgMD5Sum2 = getMD5Sum(aMsg2); 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1.getLength() == 32 && aMsgMD5Sum2.getLength() == 32 ); 812*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("source is the same, dest must be also the same", aMsgMD5Sum1.equals(aMsgMD5Sum2) == sal_True); 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir // ------------------------------------ 815*cdf0e10cSrcweir void equal_002() 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 818*cdf0e10cSrcweir rtl::OString aMsg2 = sSampleString_only_one_diff; 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir rtl::OString aMsgMD5Sum1 = getMD5Sum(aMsg1); 821*cdf0e10cSrcweir rtl::OString aMsgMD5Sum2 = getMD5Sum(aMsg2); 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("md5sum must have a length", aMsgMD5Sum1.getLength() == 32 && aMsgMD5Sum2.getLength() == 32 ); 824*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("differ only in one char", aMsgMD5Sum1.equals(aMsgMD5Sum2) == sal_False); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 828*cdf0e10cSrcweir // member functions of the current class, 829*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(equalTests); 832*cdf0e10cSrcweir CPPUNIT_TEST( equal_001 ); 833*cdf0e10cSrcweir CPPUNIT_TEST( equal_002 ); 834*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 835*cdf0e10cSrcweir }; // class create 836*cdf0e10cSrcweir 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 839*cdf0e10cSrcweir class digest_MD2 : public CppUnit::TestFixture 840*cdf0e10cSrcweir { 841*cdf0e10cSrcweir public: 842*cdf0e10cSrcweir // initialise your test code values here. 843*cdf0e10cSrcweir void setUp() 844*cdf0e10cSrcweir { 845*cdf0e10cSrcweir } 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir void tearDown() 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir } 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir // ------------------------------------ 852*cdf0e10cSrcweir void MD2_001() 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_MD2 ]; 857*cdf0e10cSrcweir CPPUNIT_ASSERT( pBuffer ); 858*cdf0e10cSrcweir memset(pBuffer, 0, RTL_DIGEST_LENGTH_MD2 ); 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); 861*cdf0e10cSrcweir sal_Int32 nLen = aMsg1.getLength(); 862*cdf0e10cSrcweir 863*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_MD2(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_MD2); 864*cdf0e10cSrcweir 865*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD2); 868*cdf0e10cSrcweir t_print("Decrypt MD2: %s\n", aStr.getStr()); 869*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD2) ); 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir delete [] pBuffer; 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 875*cdf0e10cSrcweir // member functions of the current class, 876*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_MD2); 879*cdf0e10cSrcweir CPPUNIT_TEST( MD2_001 ); 880*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 881*cdf0e10cSrcweir }; // class create 882*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 883*cdf0e10cSrcweir class digest_MD5 : public CppUnit::TestFixture 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir public: 886*cdf0e10cSrcweir // initialise your test code values here. 887*cdf0e10cSrcweir void setUp() 888*cdf0e10cSrcweir { 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir void tearDown() 892*cdf0e10cSrcweir { 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir // ------------------------------------ 895*cdf0e10cSrcweir void MD5_001() 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_MD5 ]; 900*cdf0e10cSrcweir CPPUNIT_ASSERT( pBuffer ); 901*cdf0e10cSrcweir memset(pBuffer, 0, RTL_DIGEST_LENGTH_MD5 ); 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); 904*cdf0e10cSrcweir sal_Int32 nLen = aMsg1.getLength(); 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_MD5(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_MD5); 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD5); 911*cdf0e10cSrcweir t_print("Decrypt MD5: %s\n", aStr.getStr()); 912*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD5) ); 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir delete [] pBuffer; 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 918*cdf0e10cSrcweir // member functions of the current class, 919*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_MD5); 922*cdf0e10cSrcweir CPPUNIT_TEST( MD5_001 ); 923*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 924*cdf0e10cSrcweir }; // class create 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 927*cdf0e10cSrcweir class digest_SHA : public CppUnit::TestFixture 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir public: 930*cdf0e10cSrcweir // initialise your test code values here. 931*cdf0e10cSrcweir void setUp() 932*cdf0e10cSrcweir { 933*cdf0e10cSrcweir } 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir void tearDown() 936*cdf0e10cSrcweir { 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir 939*cdf0e10cSrcweir // ------------------------------------ 940*cdf0e10cSrcweir void SHA_001() 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 943*cdf0e10cSrcweir 944*cdf0e10cSrcweir sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_SHA ]; 945*cdf0e10cSrcweir CPPUNIT_ASSERT( pBuffer ); 946*cdf0e10cSrcweir memset(pBuffer, 0, RTL_DIGEST_LENGTH_SHA); 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); 949*cdf0e10cSrcweir sal_Int32 nLen = aMsg1.getLength(); 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_SHA(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_SHA); 952*cdf0e10cSrcweir 953*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA); 956*cdf0e10cSrcweir t_print("Decrypt SHA: %s\n", aStr.getStr()); 957*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA) ); 958*cdf0e10cSrcweir 959*cdf0e10cSrcweir delete [] pBuffer; 960*cdf0e10cSrcweir } 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 963*cdf0e10cSrcweir // member functions of the current class, 964*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_SHA); 967*cdf0e10cSrcweir CPPUNIT_TEST( SHA_001 ); 968*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 969*cdf0e10cSrcweir }; // class create 970*cdf0e10cSrcweir 971*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 972*cdf0e10cSrcweir class digest_SHA1 : public CppUnit::TestFixture 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir public: 975*cdf0e10cSrcweir // initialise your test code values here. 976*cdf0e10cSrcweir void setUp() 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir void tearDown() 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir } 983*cdf0e10cSrcweir 984*cdf0e10cSrcweir // ------------------------------------ 985*cdf0e10cSrcweir void SHA1_001() 986*cdf0e10cSrcweir { 987*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_SHA1 ]; 990*cdf0e10cSrcweir CPPUNIT_ASSERT( pBuffer ); 991*cdf0e10cSrcweir memset(pBuffer, 0, RTL_DIGEST_LENGTH_SHA1); 992*cdf0e10cSrcweir 993*cdf0e10cSrcweir sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); 994*cdf0e10cSrcweir sal_Int32 nLen = aMsg1.getLength(); 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_SHA1(pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_SHA1); 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA1); 1001*cdf0e10cSrcweir t_print("Decrypt SHA1: %s\n", aStr.getStr()); 1002*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA1) ); 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir delete [] pBuffer; 1005*cdf0e10cSrcweir } 1006*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1007*cdf0e10cSrcweir // member functions of the current class, 1008*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1009*cdf0e10cSrcweir 1010*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_SHA1); 1011*cdf0e10cSrcweir CPPUNIT_TEST( SHA1_001 ); 1012*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1013*cdf0e10cSrcweir }; // class create 1014*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1015*cdf0e10cSrcweir class digest_HMAC_MD5 : public CppUnit::TestFixture 1016*cdf0e10cSrcweir { 1017*cdf0e10cSrcweir public: 1018*cdf0e10cSrcweir // initialise your test code values here. 1019*cdf0e10cSrcweir void setUp() 1020*cdf0e10cSrcweir { 1021*cdf0e10cSrcweir } 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir void tearDown() 1024*cdf0e10cSrcweir { 1025*cdf0e10cSrcweir } 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir // ------------------------------------ 1028*cdf0e10cSrcweir void HMAC_MD5_001() 1029*cdf0e10cSrcweir { 1030*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 1031*cdf0e10cSrcweir 1032*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_MD5 ]; 1033*cdf0e10cSrcweir CPPUNIT_ASSERT( pKeyBuffer ); 1034*cdf0e10cSrcweir memset(pKeyBuffer, 0, RTL_DIGEST_LENGTH_HMAC_MD5); 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_MD5 ]; 1037*cdf0e10cSrcweir CPPUNIT_ASSERT( pBuffer ); 1038*cdf0e10cSrcweir memset(pBuffer, 0, RTL_DIGEST_LENGTH_HMAC_MD5); 1039*cdf0e10cSrcweir 1040*cdf0e10cSrcweir sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); 1041*cdf0e10cSrcweir sal_Int32 nLen = aMsg1.getLength(); 1042*cdf0e10cSrcweir 1043*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_HMAC_MD5(pKeyBuffer, RTL_DIGEST_LENGTH_HMAC_MD5, pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5); 1044*cdf0e10cSrcweir 1045*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 1046*cdf0e10cSrcweir 1047*cdf0e10cSrcweir rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5); 1048*cdf0e10cSrcweir t_print("Decrypt HMAC_MD5: %s\n", aStr.getStr()); 1049*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_MD5) ); 1050*cdf0e10cSrcweir 1051*cdf0e10cSrcweir delete [] pBuffer; 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1054*cdf0e10cSrcweir // member functions of the current class, 1055*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_HMAC_MD5); 1058*cdf0e10cSrcweir CPPUNIT_TEST( HMAC_MD5_001 ); 1059*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1060*cdf0e10cSrcweir }; // class create 1061*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1062*cdf0e10cSrcweir class digest_HMAC_SHA1 : public CppUnit::TestFixture 1063*cdf0e10cSrcweir { 1064*cdf0e10cSrcweir public: 1065*cdf0e10cSrcweir // initialise your test code values here. 1066*cdf0e10cSrcweir void setUp() 1067*cdf0e10cSrcweir { 1068*cdf0e10cSrcweir } 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir void tearDown() 1071*cdf0e10cSrcweir { 1072*cdf0e10cSrcweir } 1073*cdf0e10cSrcweir 1074*cdf0e10cSrcweir // ------------------------------------ 1075*cdf0e10cSrcweir void HMAC_SHA1_001() 1076*cdf0e10cSrcweir { 1077*cdf0e10cSrcweir rtl::OString aMsg1 = sSampleString; 1078*cdf0e10cSrcweir 1079*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_SHA1 ]; 1080*cdf0e10cSrcweir CPPUNIT_ASSERT( pKeyBuffer ); 1081*cdf0e10cSrcweir memset(pKeyBuffer, 0, RTL_DIGEST_LENGTH_HMAC_SHA1); 1082*cdf0e10cSrcweir 1083*cdf0e10cSrcweir sal_uInt8 *pBuffer = new sal_uInt8[ RTL_DIGEST_LENGTH_HMAC_SHA1 ]; 1084*cdf0e10cSrcweir CPPUNIT_ASSERT( pBuffer ); 1085*cdf0e10cSrcweir memset(pBuffer, 0, RTL_DIGEST_LENGTH_HMAC_SHA1); 1086*cdf0e10cSrcweir 1087*cdf0e10cSrcweir sal_uInt8 *pMsg1 = (sal_uInt8*)aMsg1.getStr(); 1088*cdf0e10cSrcweir sal_Int32 nLen = aMsg1.getLength(); 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_HMAC_SHA1(pKeyBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1, pMsg1, nLen, pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1); 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1); 1095*cdf0e10cSrcweir t_print("Decrypt HMAC_SHA1: %s\n", aStr.getStr()); 1096*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_SHA1) ); 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir delete [] pBuffer; 1099*cdf0e10cSrcweir } 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1102*cdf0e10cSrcweir // member functions of the current class, 1103*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1104*cdf0e10cSrcweir 1105*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_HMAC_SHA1); 1106*cdf0e10cSrcweir CPPUNIT_TEST( HMAC_SHA1_001 ); 1107*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1108*cdf0e10cSrcweir }; // class create 1109*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1110*cdf0e10cSrcweir class digest_PBKDF2 : public CppUnit::TestFixture 1111*cdf0e10cSrcweir { 1112*cdf0e10cSrcweir public: 1113*cdf0e10cSrcweir // initialise your test code values here. 1114*cdf0e10cSrcweir void setUp() 1115*cdf0e10cSrcweir { 1116*cdf0e10cSrcweir } 1117*cdf0e10cSrcweir 1118*cdf0e10cSrcweir void tearDown() 1119*cdf0e10cSrcweir { 1120*cdf0e10cSrcweir } 1121*cdf0e10cSrcweir 1122*cdf0e10cSrcweir // ------------------------------------ 1123*cdf0e10cSrcweir rtl::OString /* key */ run_check_PBKDF2(rtl::OString const& _sPassword, bool _bClearSalt, sal_uInt32 _nCount) 1124*cdf0e10cSrcweir { 1125*cdf0e10cSrcweir sal_uInt32 nKeyLen = RTL_DIGEST_LENGTH_HMAC_SHA1; 1126*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 1127*cdf0e10cSrcweir CPPUNIT_ASSERT( pKeyBuffer ); 1128*cdf0e10cSrcweir memset(pKeyBuffer, 0, nKeyLen); 1129*cdf0e10cSrcweir 1130*cdf0e10cSrcweir sal_uInt8 *pPassword = (sal_uInt8*)_sPassword.getStr(); 1131*cdf0e10cSrcweir sal_Int32 nPasswordLen = _sPassword.getLength(); 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir sal_uInt32 nSaltDataLen = RTL_DIGEST_LENGTH_HMAC_SHA1; 1134*cdf0e10cSrcweir sal_uInt8 *pSaltData = new sal_uInt8[ nSaltDataLen ]; 1135*cdf0e10cSrcweir CPPUNIT_ASSERT( pSaltData ); 1136*cdf0e10cSrcweir memset(pSaltData, 0, nSaltDataLen); 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir if (! _bClearSalt) 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir // wilful contamination 1141*cdf0e10cSrcweir pSaltData[0] = 1; 1142*cdf0e10cSrcweir } 1143*cdf0e10cSrcweir 1144*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_PBKDF2(pKeyBuffer, nKeyLen, pPassword, nPasswordLen, pSaltData, nSaltDataLen, _nCount); 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); 1147*cdf0e10cSrcweir 1148*cdf0e10cSrcweir rtl::OString aKey = createHex(pKeyBuffer, nKeyLen); 1149*cdf0e10cSrcweir t_print("Key: %s\n", aKey.getStr()); 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir // rtl::OString sSalt = createHex(pSaltData, nSaltDataLen); 1152*cdf0e10cSrcweir // t_print("Salt: %s\n", sSalt.getStr()); 1153*cdf0e10cSrcweir 1154*cdf0e10cSrcweir // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) ); 1155*cdf0e10cSrcweir 1156*cdf0e10cSrcweir delete [] pSaltData; 1157*cdf0e10cSrcweir delete [] pKeyBuffer; 1158*cdf0e10cSrcweir return aKey; 1159*cdf0e10cSrcweir } 1160*cdf0e10cSrcweir 1161*cdf0e10cSrcweir void PBKDF2_001() 1162*cdf0e10cSrcweir { 1163*cdf0e10cSrcweir rtl::OString aPassword = "Password"; 1164*cdf0e10cSrcweir 1165*cdf0e10cSrcweir // all permutations 1166*cdf0e10cSrcweir run_check_PBKDF2(aPassword, false, 1); 1167*cdf0e10cSrcweir run_check_PBKDF2(aPassword, false, 2); 1168*cdf0e10cSrcweir run_check_PBKDF2(aPassword, true, 1); 1169*cdf0e10cSrcweir run_check_PBKDF2(aPassword, true, 2); 1170*cdf0e10cSrcweir run_check_PBKDF2(aPassword, false, 3); 1171*cdf0e10cSrcweir run_check_PBKDF2(aPassword, false, 4); 1172*cdf0e10cSrcweir run_check_PBKDF2(aPassword, true, 3); 1173*cdf0e10cSrcweir run_check_PBKDF2(aPassword, true, 4); 1174*cdf0e10cSrcweir } 1175*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1176*cdf0e10cSrcweir // member functions of the current class, 1177*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(digest_PBKDF2); 1180*cdf0e10cSrcweir CPPUNIT_TEST( PBKDF2_001 ); 1181*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1182*cdf0e10cSrcweir }; // class create 1183*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1184*cdf0e10cSrcweir 1185*cdf0e10cSrcweir class update : public CppUnit::TestFixture 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir public: 1188*cdf0e10cSrcweir // initialise your test code values here. 1189*cdf0e10cSrcweir void setUp() 1190*cdf0e10cSrcweir { 1191*cdf0e10cSrcweir } 1192*cdf0e10cSrcweir 1193*cdf0e10cSrcweir void tearDown() 1194*cdf0e10cSrcweir { 1195*cdf0e10cSrcweir } 1196*cdf0e10cSrcweir 1197*cdf0e10cSrcweir void update_000() 1198*cdf0e10cSrcweir { 1199*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1200*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_update(aHandle, NULL, 0); 1201*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir void updateMD2_000() 1205*cdf0e10cSrcweir { 1206*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1207*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateMD2(aHandle, NULL, 0); 1208*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1209*cdf0e10cSrcweir } 1210*cdf0e10cSrcweir 1211*cdf0e10cSrcweir void updateMD2_001() 1212*cdf0e10cSrcweir { 1213*cdf0e10cSrcweir rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 1214*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0); 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 1217*cdf0e10cSrcweir const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); 1218*cdf0e10cSrcweir 1219*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateMD2(aHandle, NULL, 0); 1220*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument ); 1221*cdf0e10cSrcweir 1222*cdf0e10cSrcweir /* rtlDigestError */ aError = rtl_digest_updateMD2(aHandle, pData, 0); 1223*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_None ); 1224*cdf0e10cSrcweir 1225*cdf0e10cSrcweir rtl_digest_destroyMD2(aHandle); 1226*cdf0e10cSrcweir } 1227*cdf0e10cSrcweir void updateMD5_000() 1228*cdf0e10cSrcweir { 1229*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1230*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateMD5(aHandle, NULL, 0); 1231*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1232*cdf0e10cSrcweir } 1233*cdf0e10cSrcweir 1234*cdf0e10cSrcweir void updateMD5_001() 1235*cdf0e10cSrcweir { 1236*cdf0e10cSrcweir // use wrong Algorithm!!! This is volitional! 1237*cdf0e10cSrcweir rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 1238*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0); 1239*cdf0e10cSrcweir 1240*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 1241*cdf0e10cSrcweir const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); 1242*cdf0e10cSrcweir sal_uInt32 nSize = ( aMsg.getLength() ); 1243*cdf0e10cSrcweir 1244*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateMD5(aHandle, pData, nSize); 1245*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError == rtl_Digest_E_Algorithm ); 1246*cdf0e10cSrcweir 1247*cdf0e10cSrcweir rtl_digest_destroyMD5(aHandle); 1248*cdf0e10cSrcweir } 1249*cdf0e10cSrcweir 1250*cdf0e10cSrcweir void updateMD5_002() 1251*cdf0e10cSrcweir { 1252*cdf0e10cSrcweir rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 1253*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != 0); 1254*cdf0e10cSrcweir 1255*cdf0e10cSrcweir rtl::OString aMsg = sSampleString; 1256*cdf0e10cSrcweir const sal_uInt8* pData = (const sal_uInt8*)aMsg.getStr(); 1257*cdf0e10cSrcweir 1258*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateMD5(aHandle, NULL, 0); 1259*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument ); 1260*cdf0e10cSrcweir 1261*cdf0e10cSrcweir /* rtlDigestError */ aError = rtl_digest_updateMD5(aHandle, pData, 0); 1262*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_None ); 1263*cdf0e10cSrcweir 1264*cdf0e10cSrcweir rtl_digest_destroyMD5(aHandle); 1265*cdf0e10cSrcweir } 1266*cdf0e10cSrcweir 1267*cdf0e10cSrcweir void updateSHA_000() 1268*cdf0e10cSrcweir { 1269*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1270*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateSHA(aHandle, NULL, 0); 1271*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1272*cdf0e10cSrcweir } 1273*cdf0e10cSrcweir 1274*cdf0e10cSrcweir void updateSHA1_000() 1275*cdf0e10cSrcweir { 1276*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1277*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateSHA1(aHandle, NULL, 0); 1278*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1279*cdf0e10cSrcweir } 1280*cdf0e10cSrcweir 1281*cdf0e10cSrcweir void updateHMAC_MD5_000() 1282*cdf0e10cSrcweir { 1283*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1284*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateHMAC_MD5(aHandle, NULL, 0); 1285*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1286*cdf0e10cSrcweir } 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir void updateHMAC_SHA1_000() 1289*cdf0e10cSrcweir { 1290*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1291*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_updateHMAC_SHA1(aHandle, NULL, 0); 1292*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1293*cdf0e10cSrcweir } 1294*cdf0e10cSrcweir 1295*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1296*cdf0e10cSrcweir // member functions of the current class, 1297*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1298*cdf0e10cSrcweir 1299*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(update); 1300*cdf0e10cSrcweir CPPUNIT_TEST(update_000); 1301*cdf0e10cSrcweir CPPUNIT_TEST(updateMD5_000); 1302*cdf0e10cSrcweir CPPUNIT_TEST(updateMD5_001); 1303*cdf0e10cSrcweir CPPUNIT_TEST(updateMD5_002); 1304*cdf0e10cSrcweir CPPUNIT_TEST(updateMD5_000); 1305*cdf0e10cSrcweir CPPUNIT_TEST(updateSHA_000); 1306*cdf0e10cSrcweir CPPUNIT_TEST(updateSHA1_000); 1307*cdf0e10cSrcweir CPPUNIT_TEST(updateHMAC_MD5_000); 1308*cdf0e10cSrcweir CPPUNIT_TEST(updateHMAC_SHA1_000); 1309*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1310*cdf0e10cSrcweir }; // class create 1311*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1312*cdf0e10cSrcweir 1313*cdf0e10cSrcweir class get : public CppUnit::TestFixture 1314*cdf0e10cSrcweir { 1315*cdf0e10cSrcweir public: 1316*cdf0e10cSrcweir // initialise your test code values here. 1317*cdf0e10cSrcweir void setUp() 1318*cdf0e10cSrcweir { 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir 1321*cdf0e10cSrcweir void tearDown() 1322*cdf0e10cSrcweir { 1323*cdf0e10cSrcweir } 1324*cdf0e10cSrcweir 1325*cdf0e10cSrcweir void get_000() 1326*cdf0e10cSrcweir { 1327*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1328*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_get(aHandle, NULL, 0); 1329*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1330*cdf0e10cSrcweir } 1331*cdf0e10cSrcweir void getMD5_000() 1332*cdf0e10cSrcweir { 1333*cdf0e10cSrcweir rtlDigest aHandle = NULL; 1334*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL, 0); 1335*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("does not handle wrong parameter", aError == rtl_Digest_E_Argument ); 1336*cdf0e10cSrcweir } 1337*cdf0e10cSrcweir void getMD5_001() 1338*cdf0e10cSrcweir { 1339*cdf0e10cSrcweir // test with wrong algorithm 1340*cdf0e10cSrcweir rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); 1341*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD2", aHandle != 0); 1342*cdf0e10cSrcweir 1343*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( aHandle ); 1344*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 1345*cdf0e10cSrcweir 1346*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL, 0); 1347*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle 2. parameter wrong", aError == rtl_Digest_E_Argument ); 1348*cdf0e10cSrcweir 1349*cdf0e10cSrcweir /* rtlDigestError */ aError = rtl_digest_getMD5(aHandle, pKeyBuffer, 0); 1350*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'handle' wrong", aError == rtl_Digest_E_Algorithm ); 1351*cdf0e10cSrcweir 1352*cdf0e10cSrcweir rtl_digest_destroyMD2(aHandle); 1353*cdf0e10cSrcweir } 1354*cdf0e10cSrcweir 1355*cdf0e10cSrcweir void getMD5_002() 1356*cdf0e10cSrcweir { 1357*cdf0e10cSrcweir rtlDigest aHandle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 1358*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", aHandle != 0); 1359*cdf0e10cSrcweir 1360*cdf0e10cSrcweir sal_uInt32 nKeyLen = rtl_digest_queryLength( aHandle ); 1361*cdf0e10cSrcweir sal_uInt8 *pKeyBuffer = new sal_uInt8[ nKeyLen ]; 1362*cdf0e10cSrcweir 1363*cdf0e10cSrcweir rtlDigestError aError = rtl_digest_getMD5(aHandle, NULL /* pKeyBuffer */ , nKeyLen); 1364*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'pData' wrong", aError == rtl_Digest_E_Argument ); 1365*cdf0e10cSrcweir 1366*cdf0e10cSrcweir /* rtlDigestError */ aError = rtl_digest_getMD5(aHandle, pKeyBuffer, 0); 1367*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("handle parameter 'nSize' wrong", aError == rtl_Digest_E_BufferSize ); 1368*cdf0e10cSrcweir 1369*cdf0e10cSrcweir rtl_digest_destroyMD5(aHandle); 1370*cdf0e10cSrcweir delete [] pKeyBuffer; 1371*cdf0e10cSrcweir } 1372*cdf0e10cSrcweir 1373*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1374*cdf0e10cSrcweir // member functions of the current class, 1375*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1376*cdf0e10cSrcweir 1377*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(get); 1378*cdf0e10cSrcweir CPPUNIT_TEST(get_000); 1379*cdf0e10cSrcweir CPPUNIT_TEST(getMD5_000); 1380*cdf0e10cSrcweir CPPUNIT_TEST(getMD5_001); 1381*cdf0e10cSrcweir CPPUNIT_TEST(getMD5_002); 1382*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1383*cdf0e10cSrcweir }; // class create 1384*cdf0e10cSrcweir 1385*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1386*cdf0e10cSrcweir class destroy : public CppUnit::TestFixture 1387*cdf0e10cSrcweir { 1388*cdf0e10cSrcweir public: 1389*cdf0e10cSrcweir // initialise your test code values here. 1390*cdf0e10cSrcweir void setUp() 1391*cdf0e10cSrcweir { 1392*cdf0e10cSrcweir } 1393*cdf0e10cSrcweir 1394*cdf0e10cSrcweir void tearDown() 1395*cdf0e10cSrcweir { 1396*cdf0e10cSrcweir } 1397*cdf0e10cSrcweir 1398*cdf0e10cSrcweir void destroy_001() 1399*cdf0e10cSrcweir { 1400*cdf0e10cSrcweir rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 1401*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("create with rtl_Digest_AlgorithmMD5", handle != 0); 1402*cdf0e10cSrcweir 1403*cdf0e10cSrcweir // not really testable 1404*cdf0e10cSrcweir // LLA: good will test. 1405*cdf0e10cSrcweir rtl_digest_destroy( handle ); 1406*cdf0e10cSrcweir } 1407*cdf0e10cSrcweir 1408*cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 1409*cdf0e10cSrcweir // member functions of the current class, 1410*cdf0e10cSrcweir // because these macros are need by auto register mechanism. 1411*cdf0e10cSrcweir 1412*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(destroy); 1413*cdf0e10cSrcweir CPPUNIT_TEST(destroy_001); 1414*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 1415*cdf0e10cSrcweir }; // class create 1416*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1417*cdf0e10cSrcweir 1418*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::create, "rtl_digest"); 1419*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD2, "rtl_digest"); 1420*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD5, "rtl_digest"); 1421*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA, "rtl_digest"); 1422*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA1, "rtl_digest"); 1423*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_MD5, "rtl_digest"); 1424*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_SHA1, "rtl_digest"); 1425*cdf0e10cSrcweir 1426*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest"); 1427*cdf0e10cSrcweir 1428*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryAlgorithm, "rtl_digest"); 1429*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryLength, "rtl_digest"); 1430*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::init, "rtl_digest"); 1431*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::equalTests, "rtl_digest"); 1432*cdf0e10cSrcweir 1433*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD2, "rtl_digest"); 1434*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD5, "rtl_digest"); 1435*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA, "rtl_digest"); 1436*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA1, "rtl_digest"); 1437*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_MD5, "rtl_digest"); 1438*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_SHA1, "rtl_digest"); 1439*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_PBKDF2, "rtl_digest"); 1440*cdf0e10cSrcweir 1441*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::update, "rtl_digest"); 1442*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::get, "rtl_digest"); 1443*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest"); 1444*cdf0e10cSrcweir } // namespace rtl_digest 1445*cdf0e10cSrcweir 1446*cdf0e10cSrcweir 1447*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1448*cdf0e10cSrcweir 1449*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions() 1450*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand. 1451*cdf0e10cSrcweir NOADDITIONAL; 1452