-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add parsing for pkcs1 and pkcs8 encoded rsa keys #38
Conversation
The build is failing on the
|
Thanks for this, and looks like some unrelated fixes are needed for the This implementation looks okay to me. I'm not super wild about the I think those should probably be methods on the individual key types. See the The |
src/lib.rs
Outdated
|
||
pub use self::key::{PublicKey, RSAPrivateKey, RSAPublicKey}; | ||
pub use self::padding::PaddingScheme; | ||
use self::parse::{parse_private_key_pkcs1, parse_private_key_pkcs8, parse_public_key_pkcs1, parse_public_key_pkcs8}; |
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 seems like this is unnecessary?
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.
I've removed it and used the full crate path where referenced.
Cool, well other than the unrelated errors from @dignifiedquire @str4d thoughts? I think we can probably simplify the implementation and eliminate the |
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.
lgtm overall, some notes, thank you!
/// following a `-----BEGIN RSA PUBLIC KEY-----` header. | ||
/// | ||
/// <https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem> | ||
pub fn from_pkcs1(der: &[u8]) -> Result<RSAPublicKey> { |
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.
could you add a doctesz for this?
/// Expects one of the following `pem` headers: | ||
/// - `-----BEGIN PRIVATE KEY-----` | ||
/// - `-----BEGIN RSA PRIVATE KEY-----` | ||
fn try_from(pem: pem::Pem) -> Result<RSAPrivateKey> { |
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.
could you add a doctest for this, so it is easy to see in the docs how it works?
/// Expects one of the following `pem` headers: | ||
/// - `-----BEGIN PUBLIC KEY-----` | ||
/// - `-----BEGIN RSA PUBLIC KEY-----` | ||
fn try_from(pem: pem::Pem) -> Result<RSAPublicKey> { |
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.
same 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.
@dignifiedquire I've added examples for all of the new functions.
e37075c
to
dcdb757
Compare
@dignifiedquire @tarcieri Anything else needed before merging? |
@aloucks sorry for the delay, I want to fix CI before merging, but it looks good thank you 👌 |
@dignifiedquire A new version of |
Adds simple functions for parsing
pkcs1
andpkcs8
encoded keys and apem
feature that re-exports thepem
crate withTryFrom
implementations.The
TryFrom
implementations will auto-detectpkcs1
orpkcs8
via the header tags.Or, manually:
Fixes #37
EDIT:
Bikeshed: Should the
rsa::parse_[public|private]_key_pkcs[1|8]
functions be prefixed withdecode_
instead?