aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Yu <yumike@google.com>2023-02-08 08:45:46 +0000
committerMike Yu <yumike@google.com>2023-02-20 13:14:45 +0000
commit8667ff4d8dfb81eb834de171421da6151a7b25ff (patch)
tree3aa10687b14d2078dfe4879e5833ab94096c3613
parent16b4e16358c86a1e31bbb75ed06e5d2a62f19fe4 (diff)
downloadDnsResolver-8667ff4d8dfb81eb834de171421da6151a7b25ff.tar.gz
Use base64 0.21.0
Bug: 268206364 Test: atest Test: browsed some websites, verified DoH worked with dns.google, dns64.dns.google, and cloudflare-dns.com Change-Id: I83799c36a1028564468b2335940a20659955fe21 Merged-In: I83799c36a1028564468b2335940a20659955fe21
-rw-r--r--doh/encoding.rs6
-rw-r--r--doh/ffi.rs3
-rw-r--r--doh/tests/doh_frontend/src/client.rs3
3 files changed, 8 insertions, 4 deletions
diff --git a/doh/encoding.rs b/doh/encoding.rs
index b2c806cc..c535c827 100644
--- a/doh/encoding.rs
+++ b/doh/encoding.rs
@@ -17,6 +17,7 @@
//! Format DoH requests
use anyhow::{anyhow, Context, Result};
+use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
use quiche::h3;
use ring::rand::SecureRandom;
use url::Url;
@@ -53,7 +54,7 @@ pub fn probe_query() -> Result<String> {
0, NS_T_AAAA, // QTYPE
0, NS_C_IN // QCLASS
];
- Ok(base64::encode_config(query, base64::URL_SAFE_NO_PAD))
+ Ok(BASE64_URL_SAFE_NO_PAD.encode(query))
}
/// Takes in a base64-encoded copy of a traditional DNS request and a
@@ -80,6 +81,7 @@ pub fn dns_request(base64_query: &str, url: &Url) -> Result<DnsRequest> {
#[cfg(test)]
mod tests {
+ use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
use quiche::h3::NameValue;
use url::Url;
@@ -109,7 +111,7 @@ mod tests {
assert_eq!(request[5].value(), b"application/dns-message");
// Verify DNS probe packet.
- let bytes = base64::decode_config(probe_query, base64::URL_SAFE_NO_PAD).unwrap();
+ let bytes = BASE64_URL_SAFE_NO_PAD.decode(probe_query).unwrap();
assert_eq!(bytes.len(), PROBE_QUERY_SIZE);
}
}
diff --git a/doh/ffi.rs b/doh/ffi.rs
index 6e9f64ad..4ae49a80 100644
--- a/doh/ffi.rs
+++ b/doh/ffi.rs
@@ -19,6 +19,7 @@
use crate::boot_time::{timeout, BootTime, Duration};
use crate::dispatcher::{Command, Dispatcher, Response, ServerInfo};
use crate::network::{SocketTagger, ValidationReporter};
+use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
use futures::FutureExt;
use libc::{c_char, int32_t, size_t, ssize_t, uint32_t, uint64_t};
use log::{error, warn};
@@ -270,7 +271,7 @@ pub unsafe extern "C" fn doh_query(
if let Some(expired_time) = BootTime::now().checked_add(t) {
let cmd = Command::Query {
net_id,
- base64_query: base64::encode_config(q, base64::URL_SAFE_NO_PAD),
+ base64_query: BASE64_URL_SAFE_NO_PAD.encode(q),
expired_time,
resp: resp_tx,
};
diff --git a/doh/tests/doh_frontend/src/client.rs b/doh/tests/doh_frontend/src/client.rs
index 0a33ef45..aead7a64 100644
--- a/doh/tests/doh_frontend/src/client.rs
+++ b/doh/tests/doh_frontend/src/client.rs
@@ -17,6 +17,7 @@
//! Client management, including the communication with quiche I/O.
use anyhow::{anyhow, bail, ensure, Result};
+use base64::{prelude::BASE64_URL_SAFE_NO_PAD, Engine};
use log::{debug, error, info, warn};
use quiche::h3::NameValue;
use std::collections::{hash_map, HashMap};
@@ -99,7 +100,7 @@ impl Client {
e.name() == b":path" && e.value().starts_with(URL_PATH_PREFIX.as_bytes())
}) {
let b64url_query = &target.value()[URL_PATH_PREFIX.len()..];
- let decoded = base64::decode_config(b64url_query, base64::URL_SAFE_NO_PAD)?;
+ let decoded = BASE64_URL_SAFE_NO_PAD.decode(b64url_query)?;
self.in_flight_queries.insert([decoded[0], decoded[1]], stream_id);
ret = decoded;
}