Properly use the odoh-rs API

This commit is contained in:
Frank Denis 2021-06-12 13:32:38 +02:00
parent a19c523cf2
commit a988eb42a2
2 changed files with 2 additions and 10 deletions

View file

@ -192,12 +192,10 @@ impl DoH {
Ok((q, context)) => (q.to_vec(), context),
Err(e) => return http_error(StatusCode::from(e)),
};
let resp = match self.proxy(query).await {
Ok(resp) => resp,
Err(e) => return http_error(StatusCode::from(e)),
};
let encrypted_resp = match context.encrypt_response(resp.packet) {
Ok(resp) => self.build_response(resp, 0u32, DoHType::Oblivious.as_str()),
Err(e) => return http_error(StatusCode::from(e)),

View file

@ -70,20 +70,14 @@ impl ODoHPublicKey {
query: query.clone(),
server_secret,
};
let mut query_bytes = Vec::new();
query
.serialize(&mut query_bytes)
.map_err(|_| DoHError::InvalidData)?;
Ok((query_bytes, context))
Ok((query.into_msg().to_vec(), context))
}
}
impl ODoHQueryContext {
pub fn encrypt_response(self, response_body: Vec<u8>) -> Result<Vec<u8>, DoHError> {
let response_nonce = rand::thread_rng().gen::<ResponseNonce>();
let response_body_ =
ObliviousDoHMessagePlaintext::deserialize(&mut bytes::Bytes::from(response_body))
.map_err(|_| DoHError::InvalidData)?;
let response_body_ = ObliviousDoHMessagePlaintext::new(response_body, 0);
let encrypted_response = odoh_rs::encrypt_response(
&self.query,
&response_body_,