Fix stack overflow when converting status enum back to u8
TODO: Add more test coverage!
This commit is contained in:
parent
bad5a230cc
commit
ff96b5b56b
2 changed files with 20 additions and 4 deletions
|
@ -70,7 +70,8 @@ where
|
||||||
let cfg = match client_cert {
|
let cfg = match client_cert {
|
||||||
None => cfg.with_no_client_auth(),
|
None => cfg.with_no_client_auth(),
|
||||||
Some(c) => {
|
Some(c) => {
|
||||||
let rustls_cert = rustls::Certificate::read_bytes(&c.der)?;
|
//let rustls_cert = rustls::Certificate::read_bytes(&c.der)?;
|
||||||
|
let rustls_cert = rustls::Certificate(c.der);
|
||||||
let cert_chain = vec![rustls_cert];
|
let cert_chain = vec![rustls_cert];
|
||||||
let key_der = rustls::PrivateKey(c.key);
|
let key_der = rustls::PrivateKey(c.key);
|
||||||
cfg.with_single_cert(cert_chain, key_der)?
|
cfg.with_single_cert(cert_chain, key_der)?
|
||||||
|
@ -79,8 +80,8 @@ where
|
||||||
let client = ClientConnection::new(Arc::new(cfg), dnsname)?;
|
let client = ClientConnection::new(Arc::new(cfg), dnsname)?;
|
||||||
let mut stream = StreamOwned::new(client, tcp_stream);
|
let mut stream = StreamOwned::new(client, tcp_stream);
|
||||||
stream.write_all(self.request.to_string().as_bytes())?;
|
stream.write_all(self.request.to_string().as_bytes())?;
|
||||||
let mut buf = vec![];
|
let mut buf = Vec::with_capacity(1024);
|
||||||
stream.read_to_end(&mut buf)?;
|
let _res = stream.read_to_end(&mut buf);
|
||||||
stream.conn.send_close_notify();
|
stream.conn.send_close_notify();
|
||||||
drop(stream);
|
drop(stream);
|
||||||
let res = buf.try_into()?;
|
let res = buf.try_into()?;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
mod error;
|
mod error;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
@ -32,7 +34,8 @@ pub enum Status {
|
||||||
impl From<Status> for u8 {
|
impl From<Status> for u8 {
|
||||||
fn from(value: Status) -> Self {
|
fn from(value: Status) -> Self {
|
||||||
match value {
|
match value {
|
||||||
Status::Input | Status::Success => value.into(),
|
Status::Input => 10,
|
||||||
|
Status::Success => 20,
|
||||||
Status::Redirect(n) => 30 + n as u8,
|
Status::Redirect(n) => 30 + n as u8,
|
||||||
Status::TemporaryFailure(n) => 40 + n as u8,
|
Status::TemporaryFailure(n) => 40 + n as u8,
|
||||||
Status::PermanentFailure(n) => 50 + n as u8,
|
Status::PermanentFailure(n) => 50 + n as u8,
|
||||||
|
@ -200,6 +203,18 @@ impl TryFrom<u8> for AuthenticationFailure {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_number_success() {
|
||||||
|
let num: u8 = Status::Success.into();
|
||||||
|
assert_eq!(num, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_number_redirect() {
|
||||||
|
let num: u8 = Status::Redirect(Redirect::Temporary).into();
|
||||||
|
assert_eq!(num, 30);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_status_success() {
|
fn parse_status_success() {
|
||||||
let status = Status::try_from(21).unwrap();
|
let status = Status::try_from(21).unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue