-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor key generation classes #2284
Conversation
de160d5
to
1aaa2e6
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2284 +/- ##
==========================================
+ Coverage 84.67% 84.81% +0.14%
==========================================
Files 116 116
Lines 23436 23292 -144
==========================================
- Hits 19844 19755 -89
+ Misses 3592 3537 -55 ☔ View full report in Codecov by Sentry. |
83d4c18
to
f7971e7
Compare
@ronaldtse @desvxx @maxirmx ping for review! |
This one is significant |
@maxirmx Thanks! Wanna make another also large PR, based on this one. |
{ | ||
if (dsa_generate(¶ms.ctx->rng, &key_, params.dsa.p_bitlen, params.dsa.q_bitlen)) { | ||
auto &dsa = dynamic_cast<const DSAKeyParams &>(params); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, but is it ok to use just static_cast here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to avoid theoretical possibility of getting wrong object here by throwing exception. Not sure how that could happen, just to be cautious.
src/lib/key_material.hpp
Outdated
size_t qbits_; | ||
|
||
public: | ||
DSAKeyParams(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qbits_ init missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually initialized in constructor implementation, but let's move it to the header for better clarity, thanks.
pgp_pubkey_alg_t alg_; | ||
pgp_hash_alg_t hash_; | ||
pgp_version_t version_; | ||
SecurityContext & ctx_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Risky solution imho (to use reference here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SecurityContext is a singleton which lives the whole life of the top-level rnp_ffi_t object, and it would be destroyed after all the internal stuff. Is this good enough or there could be other solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is singleton, I would do
static SecurityContext& SecurityContext::getContext()
and do not keep the reference
But this is probably not inportant
src/lib/pgp-key.cpp
Outdated
@@ -2618,14 +2525,14 @@ pgp_key_t::add_sub_binding(pgp_key_t & subsec, | |||
pgp_signature_t sig; | |||
sign_init(ctx.rng, sig, hash, ctx.time(), version()); | |||
sig.set_type(PGP_SIG_SUBKEY); | |||
if (binding.key_expiration) { | |||
sig.set_key_expiration(binding.key_expiration); | |||
if (binding.expiration) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be confusing - "what expiration?". IMHO keep key_expiration will be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, renamed.
key_desc.rsa.modulus_bit_len = 1024; | ||
key_desc.ctx = &global_ctx; | ||
rnp::KeygenParams keygen(PGP_PKA_RSA, global_ctx); | ||
auto & rsa = dynamic_cast<pgp::RSAKeyParams &>(keygen.key_params()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird spacing:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, unfortunately that's how clang-format 11 behaves. Don't like these as well.
5b04e51
to
43d5524
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
pgp_pubkey_alg_t alg_; | ||
pgp_hash_alg_t hash_; | ||
pgp_version_t version_; | ||
SecurityContext & ctx_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is singleton, I would do
static SecurityContext& SecurityContext::getContext()
and do not keep the reference
But this is probably not inportant
@maxirmx thanks for the review. Having static variable would have issues with multi-threaded applications, which now could use at least separate rnp_ffi_t objects in different threads. |
43d5524
to
b5b6de2
Compare
Merging with two approvals and green CI. Thanks! |
This PR refactors key generation classes.