Commit a653d251 authored by Christian Kellner's avatar Christian Kellner
Browse files

key: bolt_key_new for bolt_store_create_key

We currently don't need the store to create a new key.
parent 87fbe415
......@@ -585,7 +585,6 @@ bolt_device_authorize (BoltDevice *dev,
GError **error)
{
AuthData *auth_data;
BoltStore *store;
BoltSecurity level;
BoltKey *key;
GTask *task;
......@@ -598,14 +597,13 @@ bolt_device_authorize (BoltDevice *dev,
return FALSE;
}
store = bolt_manager_get_store (dev->mgr);
level = dev->security;
key = NULL;
if (level == BOLT_SECURITY_SECURE)
{
if (dev->store == NULL)
key = bolt_store_create_key (store, dev->uid, error);
key = bolt_key_new ();
else if (dev->key)
key = bolt_store_get_key (dev->store, dev->uid, error);
else
......
......@@ -140,6 +140,28 @@ bolt_key_class_init (BoltKeyClass *klass)
/* public methods */
BoltKey *
bolt_key_new (void)
{
BoltKey *key;
char data[BOLT_KEY_RAW_BYTES];
key = g_object_new (BOLT_TYPE_KEY, NULL);
bolt_get_random_data (data, BOLT_KEY_RAW_BYTES);
for (guint i = 0; i < BOLT_KEY_RAW_BYTES; i++)
{
char *pos = key->data + 2 * i;
gulong n = sizeof (key->data) - 2 * i;
g_snprintf (pos, n, "%02hhx", data[i]);
}
bolt_erase_n (data, sizeof (data));
key->fresh = TRUE;
return key;
}
gboolean
bolt_key_write_to (BoltKey *key,
......@@ -560,32 +582,6 @@ bolt_store_del_device (BoltStore *store,
return ok;
}
BoltKey *
bolt_store_create_key (BoltStore *store,
const char *uid,
GError **error)
{
BoltKey *key;
char data[BOLT_KEY_RAW_BYTES];
key = g_object_new (BOLT_TYPE_KEY, NULL);
bolt_get_random_data (data, BOLT_KEY_RAW_BYTES);
for (guint i = 0; i < BOLT_KEY_RAW_BYTES; i++)
{
char *pos = key->data + 2 * i;
gulong n = sizeof (key->data) - 2 * i;
g_snprintf (pos, n, "%02hhx", data[i]);
}
bolt_erase_n (data, sizeof (data));
key->fresh = TRUE;
return key;
}
BoltKeyState
bolt_store_have_key (BoltStore *store,
const char *uid)
......
......@@ -36,6 +36,8 @@ G_DECLARE_FINAL_TYPE (BoltKey, bolt_key, BOLT, KEY, GObject);
#define BOLT_KEY_RAW_CHARS 64
#define BOLT_KEY_STR_CHARS 65
BoltKey * bolt_key_new (void);
gboolean bolt_key_write_to (BoltKey *key,
int fd,
BoltSecurity *level,
......@@ -72,10 +74,6 @@ gboolean bolt_store_del_device (BoltStore *store,
const char *uid,
GError **error);
BoltKey * bolt_store_create_key (BoltStore *store,
const char *uid,
GError **error);
BoltKeyState bolt_store_have_key (BoltStore *store,
const char *uid);
......
......@@ -187,7 +187,7 @@ test_store_basic (TestStore *tt, gconstpointer user_data)
g_clear_error (&error);
g_assert_no_error (error);
key = bolt_store_create_key (tt->store, uid, &error);
key = bolt_key_new ();
g_assert_no_error (error);
g_assert_true (ok);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment