mirror of
https://github.com/DNSCrypt/doh-server.git
synced 2025-04-03 04:57:37 +03:00
Avoid unwrap()
This commit is contained in:
parent
1389c82872
commit
90c30c8905
2 changed files with 13 additions and 3 deletions
|
@ -12,6 +12,7 @@ pub enum DoHError {
|
|||
StaleKey,
|
||||
Hyper(hyper::Error),
|
||||
Io(io::Error),
|
||||
ODoHConfigError(anyhow::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for DoHError {}
|
||||
|
@ -27,6 +28,7 @@ impl std::fmt::Display for DoHError {
|
|||
DoHError::StaleKey => write!(fmt, "Stale key material"),
|
||||
DoHError::Hyper(e) => write!(fmt, "HTTP error: {}", e),
|
||||
DoHError::Io(e) => write!(fmt, "IO error: {}", e),
|
||||
DoHError::ODoHConfigError(e) => write!(fmt, "ODoH config error: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +44,7 @@ impl From<DoHError> for StatusCode {
|
|||
DoHError::StaleKey => StatusCode::UNAUTHORIZED,
|
||||
DoHError::Hyper(_) => StatusCode::SERVICE_UNAVAILABLE,
|
||||
DoHError::Io(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
DoHError::ODoHConfigError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,13 +57,20 @@ fn generate_key_pair() -> ObliviousDoHKeyPair {
|
|||
impl ODoHPublicKey {
|
||||
pub fn new() -> Result<ODoHPublicKey, DoHError> {
|
||||
let key_pair = generate_key_pair();
|
||||
let config =
|
||||
ObliviousDoHConfig::new(&key_pair.public_key.clone().to_bytes().unwrap()).unwrap();
|
||||
let config = ObliviousDoHConfig::new(
|
||||
&key_pair
|
||||
.public_key
|
||||
.clone()
|
||||
.to_bytes()
|
||||
.map_err(|e| DoHError::ODoHConfigError(e))?,
|
||||
)
|
||||
.map_err(|e| DoHError::ODoHConfigError(e))?;
|
||||
|
||||
let serialized_configs = ObliviousDoHConfigs {
|
||||
configs: vec![config.clone()],
|
||||
}
|
||||
.to_bytes()
|
||||
.unwrap()
|
||||
.map_err(|e| DoHError::ODoHConfigError(e))?
|
||||
.to_vec();
|
||||
|
||||
Ok(ODoHPublicKey {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue