Remove redundant code
This commit is contained in:
@ -4,4 +4,6 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.144", features = ["derive"] }
|
||||
serde = { version = "1.0.144", features = ["derive"] }
|
||||
rustls-pemfile = "1.0.1"
|
||||
rustls = "0.20.6"
|
37
base/src/cert_utils.rs
Normal file
37
base/src/cert_utils.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use std::error::Error;
|
||||
use std::io::{Cursor, ErrorKind};
|
||||
|
||||
use rustls::{Certificate, PrivateKey};
|
||||
use rustls_pemfile::{read_one, Item};
|
||||
|
||||
/// Parse PEM certificates bytes into a [`rustls::Certificate`] structure
|
||||
pub fn parse_pem_certificates(certs: &[u8]) -> Result<Vec<Certificate>, Box<dyn Error>> {
|
||||
Ok(rustls_pemfile::certs(&mut Cursor::new(certs))?
|
||||
.into_iter()
|
||||
.map(Certificate)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Parse PEM private key bytes into a [`rustls::PrivateKey`] structure
|
||||
pub fn parse_pem_private_key(privkey: &[u8]) -> Result<PrivateKey, Box<dyn Error>> {
|
||||
let key = match read_one(&mut Cursor::new(privkey))? {
|
||||
None => {
|
||||
Err(std::io::Error::new(
|
||||
ErrorKind::Other,
|
||||
"Failed to extract private key!",
|
||||
))?;
|
||||
unreachable!()
|
||||
}
|
||||
Some(Item::PKCS8Key(key)) => key,
|
||||
Some(Item::RSAKey(key)) => key,
|
||||
_ => {
|
||||
Err(std::io::Error::new(
|
||||
ErrorKind::Other,
|
||||
"Unsupported private key type!",
|
||||
))?;
|
||||
unreachable!();
|
||||
}
|
||||
};
|
||||
|
||||
Ok(PrivateKey(key))
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
#[derive(serde::Serialize, serde::Deserialize, Copy, Clone, Debug)]
|
||||
pub struct RelayedPort {
|
||||
pub id: usize,
|
||||
pub port: u16,
|
||||
}
|
||||
pub mod cert_utils;
|
||||
mod structs;
|
||||
|
||||
pub type RemoteConfig = Vec<RelayedPort>;
|
||||
pub use structs::{RelayedPort, RemoteConfig};
|
||||
|
7
base/src/structs.rs
Normal file
7
base/src/structs.rs
Normal file
@ -0,0 +1,7 @@
|
||||
#[derive(serde::Serialize, serde::Deserialize, Copy, Clone, Debug)]
|
||||
pub struct RelayedPort {
|
||||
pub id: usize,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
pub type RemoteConfig = Vec<RelayedPort>;
|
Reference in New Issue
Block a user