text stringlengths 0 357 |
|---|
if (!dc_key_set_from_base64(key, base64, type)) { |
dc_log_warning(context, 0, "Bad data in key \"%s\".", pathNfilename); |
goto cleanup; |
} |
success = 1; |
cleanup: |
free(buf); |
return success; |
} |
int dc_key_equals(const dc_key_t* key, const dc_key_t* o) |
{ |
if (key==NULL || o==NULL |
|| key->binary==NULL || key->bytes<=0 || o->binary==NULL || o->bytes<=0) { |
return 0; /*error*/ |
} |
if (key->bytes != o->bytes) { |
return 0; /*different size -> the keys cannot be equal*/ |
} |
if (key->type != o->type) { |
return 0; /* cannot compare public with private keys */ |
} |
return memcmp(key->binary, o->binary, o->bytes)==0? 1 : 0; |
} |
/******************************************************************************* |
* Save/Load keys |
******************************************************************************/ |
int dc_key_save_self_keypair(const dc_key_t* public_key, const dc_key_t* private_key, const char* addr, int is_default, dc_sqlite3_t* sql) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
if (public_key==NULL || private_key==NULL || addr==NULL || sql==NULL |
|| public_key->binary==NULL || private_key->binary==NULL) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(sql, |
"INSERT INTO keypairs (addr, is_default, public_key, private_key, created) VALUES (?,?,?,?,?);"); |
sqlite3_bind_text (stmt, 1, addr, -1, SQLITE_STATIC); |
sqlite3_bind_int (stmt, 2, is_default); |
sqlite3_bind_blob (stmt, 3, public_key->binary, public_key->bytes, SQLITE_STATIC); |
sqlite3_bind_blob (stmt, 4, private_key->binary, private_key->bytes, SQLITE_STATIC); |
sqlite3_bind_int64(stmt, 5, time(NULL)); |
if (sqlite3_step(stmt)!=SQLITE_DONE) { |
goto cleanup; |
} |
success = 1; |
cleanup: |
sqlite3_finalize(stmt); |
return success; |
} |
int dc_key_load_self_public(dc_key_t* key, const char* self_addr, dc_sqlite3_t* sql) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
if (key==NULL || self_addr==NULL || sql==NULL) { |
goto cleanup; |
} |
dc_key_empty(key); |
stmt = dc_sqlite3_prepare(sql, |
"SELECT public_key FROM keypairs WHERE addr=? AND is_default=1;"); |
sqlite3_bind_text (stmt, 1, self_addr, -1, SQLITE_STATIC); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
dc_key_set_from_stmt(key, stmt, 0, DC_KEY_PUBLIC); |
success = 1; |
cleanup: |
sqlite3_finalize(stmt); |
return success; |
} |
int dc_key_load_self_private(dc_key_t* key, const char* self_addr, dc_sqlite3_t* sql) |
{ |
int success = 0; |
sqlite3_stmt* stmt = NULL; |
if (key==NULL || self_addr==NULL || sql==NULL) { |
goto cleanup; |
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.