diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2024-11-11 10:06:14 +0100 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-11-26 11:03:54 +0100 |
| commit | e6fe960ac7e7e9087efc0e82a61c16c2cea107fe (patch) | |
| tree | ebdc299f4e3a5b8072b7c71c700a2f2a0cab5947 | |
| parent | 954d6f0abb42762991b20890ca9b572b9117f2fa (diff) | |
| download | mullvadvpn-e6fe960ac7e7e9087efc0e82a61c16c2cea107fe.tar.xz mullvadvpn-e6fe960ac7e7e9087efc0e82a61c16c2cea107fe.zip | |
Improve rust documentation
| -rw-r--r-- | ios/MullvadRustRuntime/include/mullvad_rust_runtime.h | 9 | ||||
| -rw-r--r-- | mullvad-encrypted-dns-proxy/src/config_resolver.rs | 4 | ||||
| -rw-r--r-- | mullvad-encrypted-dns-proxy/src/state.rs | 2 | ||||
| -rw-r--r-- | mullvad-ios/src/encrypted_dns_proxy.rs | 14 |
4 files changed, 24 insertions, 5 deletions
diff --git a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h index ad13d1f6e0..a45c6ed6c3 100644 --- a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h +++ b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h @@ -33,6 +33,15 @@ extern const uint16_t CONFIG_SERVICE_PORT; /** * Initializes a valid pointer to an instance of `EncryptedDnsProxyState`. + * + * # Safety + * + * * [domain_name] must not be non-null. + * + * * [domain_name] pointer must be [valid](core::ptr#safety) + * + * * The caller must ensure that the pointer to the [domain_name] string contains a nul terminator + * at the end of the string. */ struct EncryptedDnsProxyState *encrypted_dns_proxy_init(const char *domain_name); diff --git a/mullvad-encrypted-dns-proxy/src/config_resolver.rs b/mullvad-encrypted-dns-proxy/src/config_resolver.rs index 96aa64e938..82edd886f5 100644 --- a/mullvad-encrypted-dns-proxy/src/config_resolver.rs +++ b/mullvad-encrypted-dns-proxy/src/config_resolver.rs @@ -61,12 +61,12 @@ pub fn default_resolvers() -> Vec<Nameserver> { ] } +/// Calls [resolve_configs] with a given `domain` using known DoH resolvers provided by [default_resolvers] pub async fn resolve_default_config(domain: &str) -> Result<Vec<config::ProxyConfig>, Error> { - // TODO: We should remove the default value here and just force the callers to provide a domain instead resolve_configs(&default_resolvers(), domain).await } -/// Look up the `domain` towards the given `resolvers`, and try to deserialize all the returned +/// Looks up the `domain` towards the given `resolvers`, and try to deserialize all the returned /// AAAA records into [`ProxyConfig`](config::ProxyConfig)s. pub async fn resolve_configs( resolvers: &[Nameserver], diff --git a/mullvad-encrypted-dns-proxy/src/state.rs b/mullvad-encrypted-dns-proxy/src/state.rs index 3d6a26a0ce..8b6c3c9886 100644 --- a/mullvad-encrypted-dns-proxy/src/state.rs +++ b/mullvad-encrypted-dns-proxy/src/state.rs @@ -58,7 +58,7 @@ impl EncryptedDnsProxyState { Some(selected_config) } - /// Fetch a config, but error out only when no existing configuration was there. + /// Fetch a config from `domain`, but error out only when no existing configuration was there. pub async fn fetch_configs(&mut self, domain: &str) -> Result<(), FetchConfigError> { match resolve_default_config(domain).await { Ok(new_configs) => { diff --git a/mullvad-ios/src/encrypted_dns_proxy.rs b/mullvad-ios/src/encrypted_dns_proxy.rs index d371044d48..3c89faf895 100644 --- a/mullvad-ios/src/encrypted_dns_proxy.rs +++ b/mullvad-ios/src/encrypted_dns_proxy.rs @@ -82,12 +82,22 @@ impl EncryptedDnsProxyState { } /// Initializes a valid pointer to an instance of `EncryptedDnsProxyState`. +/// +/// # Safety +/// +/// * [domain_name] must not be non-null. +/// +/// * [domain_name] pointer must be [valid](core::ptr#safety) +/// +/// * The caller must ensure that the pointer to the [domain_name] string contains a nul terminator +/// at the end of the string. #[no_mangle] pub unsafe extern "C" fn encrypted_dns_proxy_init( domain_name: *const c_char, ) -> *mut EncryptedDnsProxyState { - let domain = unsafe { - let c_str = CStr::from_ptr(domain_name); + // SAFETY: domain_name points to a valid region of memory and contains a nul terminator. + let domain = { + let c_str = unsafe { CStr::from_ptr(domain_name) }; String::from_utf8_lossy(c_str.to_bytes()) }; |
