test-crypto.c 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <glib.h>
  2. #include <gio/gio.h>
  3. #include "iridium-crypto.h"
  4. static void
  5. test_hexlify (void)
  6. {
  7. guint8 data[] = { 'A', '1', 'x', ';' };
  8. gchar *hexlified = iridium_crypto_hexlify (data, 4);
  9. g_assert_cmpstr (hexlified, ==, "4131783b");
  10. g_free (hexlified);
  11. }
  12. static void
  13. test_unhexlify (void)
  14. {
  15. gchar *hexlified = "466f6f62617221";
  16. guint8 *data = iridium_crypto_unhexlify (hexlified, strlen (hexlified));
  17. g_assert_cmpstr ((gchar *) data, ==, "Foobar!");
  18. g_free (data);
  19. }
  20. static void
  21. test_decrypt_003 (void)
  22. {
  23. GBytes *data;
  24. data = g_resources_lookup_data ("/net/bloerg/Test/dumps/003.json",
  25. G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
  26. g_assert_nonnull (data);
  27. g_bytes_unref (data);
  28. }
  29. int
  30. main (int argc, char * argv[])
  31. {
  32. g_test_init (&argc, &argv, NULL);
  33. g_test_add_func ("/crypto/hexlify", test_hexlify);
  34. g_test_add_func ("/crypto/unhexlify", test_unhexlify);
  35. g_test_add_func ("/crypto/decrypt/003", test_decrypt_003);
  36. return g_test_run ();
  37. }