Repository navigation
Conversation
8e4c42b to
6657a4b
Compare
|
Some things to work out
|
34c7c9f to
212e628
Compare
There was a problem hiding this comment.
I'm very much in favor of simplifying this. It is actually quite hard to find how asymmetric keys are exported into containers in our API.
Should we take the opportunity to move this to
Private_Key
This would be more in line with what #4318 currently proposes for signing. If we were to fully embrace this API design for key export, we'd probably end up with something like:
auto sk = create_private_key("RSA", rng);
auto pkcs8 = sk.export()
.with_cipher("AES-128/CBC")
.with_pbkdf("Scrypt")
.with_rng(rng)
.as_pem();... admittedly, this would add quite a bit of (internal) boilerplate for the Options-builder plumbing. But, to my mind, such an API is quite ergonomic for the user, since they don't have to learn much library-specific type vocabulary. Just type sk. and your IDE will suggest .export(), just type . again and you'll be presented with the different options you could use.
Such an API would also conveniently cover "unencrypted export". Though, for safety reasons, I'd suggest to guard that like so:
auto unencrypted = sk.export()
.without_encryption() // to deliberately request "unsafe"
.as_pem();| // The default encryption cipher | ||
| // | ||
| // This may change over time | ||
| static std::string default_cipher(); | ||
|
|
||
| // The default password hash | ||
| // | ||
| // This may change over time | ||
| // | ||
| // TODO(Botan4) Consider changing this to Scrypt | ||
| static std::string default_pwhash(); | ||
|
|
||
| // The default password hash duration | ||
| // | ||
| // This may change over time | ||
| static std::chrono::milliseconds default_pwhash_duration(); |
There was a problem hiding this comment.
Do those need to be public?
| #include <optional> | ||
| #include <span> | ||
| #include <string_view> | ||
| #include <variant> |
There was a problem hiding this comment.
Seems orphaned and unused. I'm guessing you considered it to distinguish duration and iterations.
|
I toyed with a builder idea during development but I figured I would let you be the one to suggest it :P |
|
Perhaps we should pull the reusable portions of the |
Quite a few interfaces exist for this but there really are only two things that change between them: if the PBKDF runtime is specified in "iterations" or in a duration, and if the result is PEM encoded or not. Add a new single interface for PKCS8 encryption, PKCS8::encrypt_private_key, then define all of the previously existing functions in terms of that.
212e628 to
d70034d
Compare
Quite a few interfaces exist for this but there really are only two things that change between them: if the PBKDF runtime is specified in "iterations" or in a duration, and if the result is PEM encoded or not.
Add a new single interface for PKCS8 encryption, PKCS8::encrypt_private_key, then define all of the previously existing functions in terms of that.