mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-22 18:14:11 +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:
@@ -39,7 +39,6 @@ mysql = [
|
||||
"sha2",
|
||||
"generic-array",
|
||||
"num-bigint",
|
||||
"base64",
|
||||
"digest",
|
||||
"rand",
|
||||
"rsa",
|
||||
@@ -144,7 +143,7 @@ percent-encoding = "2.1.0"
|
||||
parking_lot = "0.11.0"
|
||||
rand = { version = "0.8.3", default-features = false, optional = true, features = ["std", "std_rng"] }
|
||||
regex = { version = "1.3.9", optional = true }
|
||||
rsa = { version = "0.4.0", optional = true }
|
||||
rsa = { version = "0.5.0", optional = true }
|
||||
rustls = { version = "0.19.0", features = ["dangerous_configuration"], optional = true }
|
||||
serde = { version = "1.0.106", features = ["derive", "rc"], optional = true }
|
||||
serde_json = { version = "1.0.51", features = ["raw_value"], optional = true }
|
||||
|
||||
@@ -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