-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
586 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use rsa::pkcs1::{DecodeRsaPrivateKey, DecodeRsaPublicKey}; | ||
use crate::error::{Result, Error}; | ||
use crate::pubkey::{RsaPrivkey, RsaPubkey}; | ||
|
||
/// Decode a private RSA key from PKCS#1 PEM format without decryption. | ||
/// | ||
/// Files in this format start with `-----BEGIN RSA PRIVATE KEY-----`, followed by base64-encoded | ||
/// DER data (see [`decode_pkcs1_der_privkey()`]). | ||
/// | ||
/// Encrypted PKCS#1 keys have a PEM header such as `Proc-Type: 4,ENCRYPTED` after the `-----BEGIN | ||
/// RSA PRIVATE KEY-----` header. At this moment, we do not support such keys. | ||
pub fn decode_pkcs1_pem_privkey_nopass(pem_data: &str) -> Result<RsaPrivkey> { | ||
let privkey = rsa::RsaPrivateKey::from_pkcs1_pem(pem_data).map_err(Error::Pkcs1)?; | ||
Ok(RsaPrivkey { privkey }) | ||
} | ||
|
||
/// Decode a private RSA key from PKCS#1 binary DER format. | ||
/// | ||
/// You will rarely encounter the binary DER format in the wild. If you key starts with `-----BEGIN | ||
/// RSA PRIVATE KEY-----`, the DER data is wrapped in PEM format (see | ||
/// [`decode_pkcs1_pem_privkey_nopass()`]). | ||
pub fn decode_pkcs1_der_privkey(der_data: &[u8]) -> Result<RsaPrivkey> { | ||
let privkey = rsa::RsaPrivateKey::from_pkcs1_der(der_data).map_err(Error::Pkcs1)?; | ||
Ok(RsaPrivkey { privkey }) | ||
} | ||
|
||
/// Decode a public RSA key from PKCS#1 PEM format. | ||
/// | ||
/// Files in this format start with `-----BEGIN RSA PUBLIC KEY-----`, followed by base64-encoded | ||
/// DER data (see [`decode_pkcs1_der_pubkey()`]). | ||
pub fn decode_pkcs1_pem_pubkey(pem_data: &str) -> Result<RsaPubkey> { | ||
let pubkey = rsa::RsaPublicKey::from_pkcs1_pem(pem_data).map_err(Error::Pkcs1)?; | ||
Ok(RsaPubkey { pubkey }) | ||
} | ||
|
||
/// Decode a public RSA key from PKCS#1 binary DER format. | ||
/// | ||
/// You will rarely encounter the binary DER format in the wild. If you key starts with `-----BEGIN | ||
/// RSA PUBLIC KEY-----`, the DER data is wrapped in PEM format (see | ||
/// [`decode_pkcs1_pem_pubkey()`]). | ||
pub fn decode_pkcs1_der_pubkey(der_data: &[u8]) -> Result<RsaPubkey> { | ||
let pubkey = rsa::RsaPublicKey::from_pkcs1_der(der_data).map_err(Error::Pkcs1)?; | ||
Ok(RsaPubkey { pubkey }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
Proc-Type: 4,ENCRYPTED | ||
DEK-Info: AES-256-CTR,E235B936ECDB5ED10F40C646EFBFCABB | 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72fGXjR1WN8cOhbSfz5XqwRj6qUljgYhUu | ||
g7kHfd89Gbn5eyyxP8Fb6bE3oTbn8EV78uEqkaag6KsC4yMXaNldushowosbjcZ2 | ||
rnHKlSI0YJD4vxCaQsamlTRSjPCcmZcCbzo0EEP6Lyo1jFkxHtaCnKtVNoRIQyfP | ||
o5JZpZNQL0+PHN7SiY2Tn41axZsmvJ3kms6CUnwDhve1BakYFpuo1zDef4Ugu4Bw | ||
0E40wPsZZqjMsqazIRLRYB3+o7hlPYhtRJw8Jl6tymcrb1cZ8rvfZ2RJPmb91Js/ | ||
9tfwKmA9yc5ScCSfi7aVa3b/ROu9hOCeXtWGTd0fFKCobh/Fz5eOAvXKLM1aTa8m | ||
VPr22x2q4NzWaGjYAE8kDQ3M7cwI2EgCoePNkqEwiuyVHIYrXY+kIJYwalxvAcdY | ||
NhH7DZ9eRPoLX7Xfcetc0vmHju6c2n5MtPXhEK/EwnGVVzGYe3K/uX5d6pGwuNgP | ||
2gG6s0nvDfzcJBZcGPtbsF0kufEWWsDU5udC/96uVmRas7C+bWo/pi9b7T05yvvd | ||
hIjVvS7SgXC2XhG3PtjHrgspN/H/lNQzGoBT8XuADVzPepbC7dRR | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxEnHFfey5WPgemz3T2qn | ||
alJU59OpzEJKAB8yFr9gur/4axy0Nqptp++Hs4X4No1VZWqqv+frNingB6w8p/x/ | ||
nX9oSlkdzbY38AiqRXQn/SfIaW8wyZvMZHBgcscu7KQ1FVpVVLbNmvNjQINJGQVs | ||
w177RmoS3lV9nEFECDEBYSeiASIZtZ2SxPNqXeiRIHMXA7G5QDUVbMnMc6VMVi2F | ||
o/yYfMAK+02zmOzCnEsaIKLAV8GHbQislRrPps4sZcv4hTHX005IAAcIKfFl9YZT | ||
28IQbHcl69UwNQLlhBGQwlRMnfPkttvUpCMEp619NcTvlCSZfd0PH8uOPOcr5R1s | ||
4QIDAQAB | ||
-----END PUBLIC KEY----- |
Oops, something went wrong.