2
0

testmd5.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <assert.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include "apr_md5.h"
  20. #include "apr_xlate.h"
  21. #include "apr_general.h"
  22. #include "abts.h"
  23. #include "testutil.h"
  24. static struct {
  25. const char *string;
  26. const char *digest;
  27. } md5sums[] =
  28. {
  29. {"Jeff was here!",
  30. "\xa5\x25\x8a\x89\x11\xb2\x9d\x1f\x81\x75\x96\x3b\x60\x94\x49\xc0"},
  31. {"01234567890aBcDeFASDFGHJKLPOIUYTR"
  32. "POIUYTREWQZXCVBN LLLLLLLLLLLLLLL",
  33. "\xd4\x1a\x06\x2c\xc5\xfd\x6f\x24\x67\x68\x56\x7c\x40\x8a\xd5\x69"},
  34. {"111111118888888888888888*******%%%%%%%%%%#####"
  35. "142134u8097289720432098409289nkjlfkjlmn,m.. ",
  36. "\xb6\xea\x5b\xe8\xca\x45\x8a\x33\xf0\xf1\x84\x6f\xf9\x65\xa8\xe1"},
  37. {"01234567890aBcDeFASDFGHJKLPOIUYTR"
  38. "POIUYTREWQZXCVBN LLLLLLLLLLLLLLL"
  39. "01234567890aBcDeFASDFGHJKLPOIUYTR"
  40. "POIUYTREWQZXCVBN LLLLLLLLLLLLLLL"
  41. "1",
  42. "\xd1\xa1\xc0\x97\x8a\x60\xbb\xfb\x2a\x25\x46\x9d\xa5\xae\xd0\xb0"}
  43. };
  44. static int num_sums = sizeof(md5sums) / sizeof(md5sums[0]);
  45. static int count;
  46. static void test_md5sum(abts_case *tc, void *data)
  47. {
  48. apr_md5_ctx_t context;
  49. unsigned char digest[APR_MD5_DIGESTSIZE];
  50. const void *string = md5sums[count].string;
  51. const void *sum = md5sums[count].digest;
  52. unsigned int len = strlen(string);
  53. ABTS_ASSERT(tc, "apr_md5_init", (apr_md5_init(&context) == 0));
  54. ABTS_ASSERT(tc, "apr_md5_update",
  55. (apr_md5_update(&context, string, len) == 0));
  56. ABTS_ASSERT(tc, "apr_md5_final", (apr_md5_final(digest, &context)
  57. == 0));
  58. ABTS_ASSERT(tc, "check for correct md5 digest",
  59. (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
  60. }
  61. abts_suite *testmd5(abts_suite *suite)
  62. {
  63. suite = ADD_SUITE(suite);
  64. for (count=0; count < num_sums; count++) {
  65. abts_run_test(suite, test_md5sum, NULL);
  66. }
  67. return suite;
  68. }