Skip to content

Commit

Permalink
CAA value is binary
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed May 26, 2024
1 parent fc7de4b commit 4e452c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- CAA record value is bytes, not a string

## 9.2.1 (26 May 2024)

- Include the whole API in docs
Expand Down
7 changes: 1 addition & 6 deletions examples/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ mod example {
Ok(ref caa_results) => {
println!("Successful CAA lookup...");
for caa_result in caa_results {
println!(
"critical: {}, property: {}, value: {}",
caa_result.critical(),
caa_result.property().to_string_lossy(),
caa_result.value().to_string_lossy()
);
println!("{}", caa_result);
}
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/caa.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::os::raw::{c_int, c_uchar, c_void};
use std::ptr;
use std::slice;
use std::{fmt, ptr, slice, str};

use itertools::Itertools;

Expand Down Expand Up @@ -114,12 +112,8 @@ impl<'a> CAAResult<'a> {
}

/// The value represented by this `CAAResult`.
///
/// In practice this is very likely to be a valid UTF-8 string, but the underlying `c-ares`
/// library does not guarantee this - so we leave it to users to decide whether they prefer a
/// fallible conversion, a lossy conversion, or something else altogether.
pub fn value(self) -> &'a CStr {
unsafe { CStr::from_ptr(self.caa_reply.value.cast()) }
pub fn value(self) -> &'a [u8] {
unsafe { slice::from_raw_parts(self.caa_reply.value, self.caa_reply.length) }
}
}

Expand All @@ -131,11 +125,8 @@ impl<'a> fmt::Display for CAAResult<'a> {
"Property: {}, ",
self.property().to_str().unwrap_or("<not utf8>")
)?;
write!(
fmt,
"Value: {}",
self.value().to_str().unwrap_or("<not utf8>")
)
let value = str::from_utf8(self.value()).unwrap_or("<binary>");
write!(fmt, "Value: {}", value)
}
}

Expand Down

0 comments on commit 4e452c0

Please sign in to comment.