mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-21 09:34:02 +00:00
Update rsa crate to 0.5 (#1572)
* Update rsa crate to 0.5 * Don't do pem decoding ourselves
This commit is contained in:
@@ -3,7 +3,7 @@ use bytes::Bytes;
|
||||
use digest::{Digest, FixedOutput};
|
||||
use generic_array::GenericArray;
|
||||
use rand::thread_rng;
|
||||
use rsa::{PaddingScheme, PublicKey, RSAPublicKey};
|
||||
use rsa::{pkcs8::FromPublicKey, PaddingScheme, PublicKey, RsaPublicKey};
|
||||
use sha1::Sha1;
|
||||
use sha2::Sha256;
|
||||
|
||||
@@ -180,22 +180,12 @@ fn to_asciz(s: &str) -> Vec<u8> {
|
||||
}
|
||||
|
||||
// https://docs.rs/rsa/0.3.0/rsa/struct.RSAPublicKey.html?search=#example-1
|
||||
fn parse_rsa_pub_key(key: &[u8]) -> Result<RSAPublicKey, Error> {
|
||||
let key = std::str::from_utf8(key).map_err(Error::protocol)?;
|
||||
fn parse_rsa_pub_key(key: &[u8]) -> Result<RsaPublicKey, Error> {
|
||||
let pem = std::str::from_utf8(key).map_err(Error::protocol)?;
|
||||
|
||||
// This takes advantage of the knowledge that we know
|
||||
// we are receiving a PKCS#8 RSA Public Key at all
|
||||
// times from MySQL
|
||||
|
||||
let encoded =
|
||||
key.lines()
|
||||
.filter(|line| !line.starts_with("-"))
|
||||
.fold(String::new(), |mut data, line| {
|
||||
data.push_str(&line);
|
||||
data
|
||||
});
|
||||
|
||||
let der = base64::decode(&encoded).map_err(Error::protocol)?;
|
||||
|
||||
RSAPublicKey::from_pkcs8(&der).map_err(Error::protocol)
|
||||
RsaPublicKey::from_public_key_pem(&pem).map_err(Error::protocol)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user