module util; import std.format; import std.json; import slf4d; import deimos.openssl.rsa; import deimos.openssl.pem; void optional(T)(ref JSONValue val, string key, ref T receiver) { const(JSONValue)* p = key in val; if (p == null) return; static if (is(JSONValue == T)) receiver = *p; else receiver = (*p).get!T; } T optional(T)(ref JSONValue val, string key) { T t; optional(val, key, t); return t; } void required(T)(ref JSONValue val, string key, ref T receiver) { receiver = val[key].get!T; } void generateRSA() { RSA* rsa = RSA_generate_key(2048, 3, null, null); BIO* bio = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey(bio, rsa, null, null, 0, null, null); int keyLen = BIO_pending(bio); char[] pemKey = new char[keyLen + 1]; BIO_read(bio, pemKey.ptr, keyLen); BIO_free_all(bio); RSA_free(rsa); infoF!"private key: %s"(pemKey); }