b64_test.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. *******************************************************************************
  3. \file b64_test.c
  4. \brief Tests for base64 encoding
  5. \project bee2/test
  6. \created 2016.06.16
  7. \version 2016.06.16
  8. \copyright The Bee2 authors
  9. \license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
  10. *******************************************************************************
  11. */
  12. #include <bee2/core/b64.h>
  13. #include <bee2/core/mem.h>
  14. #include <bee2/crypto/belt.h>
  15. /*
  16. *******************************************************************************
  17. Тестирование
  18. *******************************************************************************
  19. */
  20. bool_t b64Test()
  21. {
  22. octet buf[256];
  23. char b64[255 / 3 * 4 + 1];
  24. size_t count;
  25. // валидация
  26. if (!b64IsValid("1234") ||
  27. b64IsValid("AbC=") ||
  28. !b64IsValid("AbE=") ||
  29. b64IsValid("AbCBD4==") ||
  30. !b64IsValid("AbCBDg==") ||
  31. b64IsValid("AbC78a8@") ||
  32. b64IsValid("AbC78a8") ||
  33. b64IsValid("AbC7===") ||
  34. b64IsValid("Ab=7=="))
  35. return FALSE;
  36. // кодировать / декодировать
  37. for (count = 0; count < 256; ++count)
  38. {
  39. size_t t;
  40. b64From(b64, beltH(), count);
  41. b64To(0, &t, b64);
  42. if (t != count)
  43. return FALSE;
  44. t += 1;
  45. b64To(buf, &t, b64);
  46. if (t != count)
  47. return FALSE;
  48. if (!memEq(buf, beltH(), count))
  49. return FALSE;
  50. }
  51. // все нормально
  52. return TRUE;
  53. }