module AccountKey
Constants
- VERSION
Public Class Methods
create()
click to toggle source
static VALUE account_create_key(VALUE module) {
EVP_PKEY_CTX *ctx;
VALUE key_class = rb_const_get(module, rb_intern("Key"));
VALUE id_new = rb_intern("new");
VALUE klass = rb_funcall(key_class, id_new, 0);
convex_account_p account = NULL;
Data_Get_Struct(klass, convex_account_t , account);
if (!account) {
return 0;
}
// create the openssl ctx for ED25519 keys
ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, NULL);
if (!ctx) {
return 0;
}
EVP_PKEY_keygen_init(ctx);
// generate a new key
EVP_PKEY_keygen(ctx, &account->key);
set_raw_public_key(account);
// now free the openssl ctx
EVP_PKEY_CTX_free(ctx);
return klass;
}
create_from_text(p1, p2)
click to toggle source
static VALUE account_create_key_from_text(VALUE module, VALUE text, VALUE password) {
VALUE result = 0;
VALUE key_class = rb_const_get(module, rb_intern("Key"));
VALUE id_new = rb_intern("new");
VALUE klass = rb_funcall(key_class, id_new, 0);
convex_account_p account = NULL;
Data_Get_Struct(klass, convex_account_t , account);
if(!account) {
return result;
}
if (account->key) {
EVP_PKEY_free(account->key);
account->key = NULL;
}
char *text_ptr = StringValueCStr(text);
char *password_ptr = StringValueCStr(password);
BIO *memory = BIO_new(BIO_s_mem());
BIO_puts(memory, text_ptr);
account->key = PEM_read_bio_PrivateKey(memory, NULL, NULL, (void *)password_ptr);
BIO_free_all(memory);
if (!account->key) {
return result;
}
set_raw_public_key(account);
return klass;
}