| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include <glib.h>
- #include <gio/gio.h>
- #include <string.h>
- #include <json-glib/json-glib.h>
- #include "iridium-crypto.h"
- #include "iridium-standard-file.h"
- typedef struct {
- JsonParser *parser;
- } Dump;
- static void
- dump_003_set_up (Dump *dump, gconstpointer user_data)
- {
- GBytes *data;
- GError *error = NULL;
- data = g_resources_lookup_data ("/net/bloerg/Test/dumps/003.json",
- G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
- g_assert_nonnull (data);
- dump->parser = json_parser_new_immutable ();
- g_assert (json_parser_load_from_data (dump->parser, g_bytes_get_data (data, NULL),
- g_bytes_get_size(data), &error));
- g_assert_null (error);
- g_bytes_unref (data);
- }
- static void
- dump_003_tear_down (Dump *dump, gconstpointer user_data)
- {
- g_object_unref (dump->parser);
- }
- static void
- test_hexlify (void)
- {
- guint8 data[] = { 'A', '1', 'x', ';' };
- gchar *hexlified = iridium_crypto_hexlify (data, 4);
- g_assert_cmpstr (hexlified, ==, "4131783b");
- g_free (hexlified);
- }
- static void
- test_unhexlify (void)
- {
- gchar *hexlified = "466f6f62617221";
- guint8 *data = iridium_crypto_unhexlify (hexlified, strlen (hexlified));
- g_assert_cmpstr ((gchar *) data, ==, "Foobar!");
- g_free (data);
- }
- static void
- test_decrypt_003_wrong_password (Dump *dump, gconstpointer user_data)
- {
- IridiumAuthParams *params;
- GList *items;
- GError *error;
- params = iridium_crypto_auth_params_new ();
- iridium_crypto_derive_keys (params, "foo");
- items = iridium_standard_file_get_items (dump->parser, params, &error);
- g_assert_null (items);
- iridium_crypto_auth_params_free (params);
- }
- int
- main (int argc, char * argv[])
- {
- g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/crypto/hexlify", test_hexlify);
- g_test_add_func ("/crypto/unhexlify", test_unhexlify);
- g_test_add ("/crypto/decrypt/003/wrong-password", Dump, NULL,
- dump_003_set_up, test_decrypt_003_wrong_password, dump_003_tear_down);
- return g_test_run ();
- }
|