Commit Graph
26 Commits
Author SHA1 Message Date
arya dradjicaandarya dradjica e8e40c6641 Disallow elided lifetimes in paths
This language feature is deprecated, but the lint for it is not
enabled by default.  Enabling the lint and fixing all occurrences also
resolves some new Clippy lints.  This does not affect the API or
behaviour of the code in any way.
2025-06-24 11:59:06 +00:00
93a0053596 Apply fixes for new issues found by Clippy 1.83.0 (#460)
Co-authored-by: Terts Diepraam <terts.diepraam@gmail.com>
2024-11-29 15:33:18 +01:00
Terts DiepraamandGitHub dab2a90563 Refactor pointer casts to transmutes and annotate with repr(transparent) (#324)
This PR adds #[repr(transparent)] to various wrapper types and replaces
pointer cases with mem::transmute.
2024-06-03 16:23:41 +02:00
Terts DiepraamandGitHub f84abe0da8 Fix rustdoc links across the repo (#319) 2024-05-29 16:48:40 +02:00
Martin HoffmannandGitHub 1466e1e092 Partially seal error types. (#277)
This PR looks at all the error types and splits them into meaningful error
information, which will be available as enum variants, and internals, which
will be hidden away behind opaque structs. For the former case, we will
still use enums directly rather than have error kind enums. These will not
be non-exhaustive since they should really cover all possible cases and
exhaustive matching should work.

This is a breaking change.
2024-03-21 17:26:56 +01:00
Martin HoffmannandGitHub 7a0819dc90 Fix TXT record serialization. (#272)
This PR fixes TXT record data serialization for human-readable formats. TXT
record data is now serialized as a sequence of character strings. It also
deserializes from such a sequence. If supported by the format, it
alternatively deserializes from a string that is broken up into 255 octet
chunks if necessary.

It uses a newly added helper type base::charstr::DeserializeCharStrSeed that
deserializes character strings by appending them to an octets builder. Since
this may be useful for other cases, it has been made public.

This is a breaking change.
2024-03-18 12:44:11 +01:00
Martin HoffmannandGitHub 1e25edb277 Fix nightly warnings. (#280)
This PR fixes warnings from lints added to the nightly compiler. It also
changes the CI workflow to error out when there are warnings.
2024-02-27 12:59:19 +01:00
Martin HoffmannandGitHub 74ce3dd62b Redesign CharStr formatting and serialization. (#270)
This PR redesigns the conversion of CharStr from and to text formats.

It distinguishes between three text formats: quoted and unquoted
representation format (i.e., what’s used in zonefiles) and a serialization
format which is an unquoted format with only backslash and non-printable
octets escaped. The latter will be used in serialization but also by default
for Display. This makes it reversible with the FromStr implementation but
avoids escaping white space. Methods for explicitly displaying in quoted and
unquoted representation format are provided.

Serialization works mostly as before but uses the serialization format
rather than the unquoted representation format in human-readable formats. It
still uses the raw octets in binary formats.

The PR adds proper documentation for all of it to the type.
2024-02-09 13:33:17 +01:00
Martin HoffmannandGitHub 8b97e43cb0 Reject empty TXT record data and never build it. (#267)
This PR changes the rdata::Txt type to reject empty record data as invalid.

RFC 1035 states that the TXT-DATA is “One or more <character-string>s”. This
means that there will have to be at least the length octet of the first
character string.

The PR also adjusts the TxtBuilder to never return a empty data. Since this
requires being able to return an error in TxtBuilder:.finish, this is a
breaking change. While at it, the PR also adds more control over the created
character strings by making close_char_str public and adding a new
append_char_str method.

The PR also improves the documentation for the TXT record data types.
2024-02-07 09:49:34 +01:00
Martin HoffmannandGitHub db012e4ad9 Fix Display impl for Txt and add CharStr::display_quoted. (#261)
This PR fixes the Display implementation for the Txt record data type. It
now prints each character string separately and quoted. It uses the new
CharStr::display_quoted method that prints the content of a character string
quoted and with only necessary characters escaped.
2024-02-05 10:29:12 +01:00
HugoandGitHub 98669b2f62 Mark function without side effects as must_use (#228)
This hint will make the compiler warn consumers of this library if they
ever call one of these functions without using its return value.
2023-10-05 19:07:40 +02:00
Martin HoffmannandGitHub 77306c84bb Remove Deref and DerefMut from types that shouldn’t have them. (#205)
This PR removes the Deref and DerefMut impls from types that aren’t smart
pointers and thus shouldn’t really have them according to the advise given
in the documentation.

Where appropriate, it adds len and is_empty methods. Additional methods
likely should be added later as well.

In particular:

   o  Removed impls of Deref and (if present) DerefMut for the following
      types: CharStr, CharStrBuilder, DnameBuilder, Label, A, Aaaa, all
      record types that wrap a domain name, Nsec3Salt, OwnerHash,
      SearchList, ServerList. Where necessary, len and is_empty were added.

   o  IntoIterator for Label has a changed Self::Item.

This is a breaking change.
2023-05-11 10:38:26 +02:00
Jonas KruckenbergandGitHub 1c43ebb2bd Add MAX_LEN constants to length-limited types. (#201)
This PR adds a MAX_LEN associated constant to various types that are
lenght-limited octets sequences.
2023-05-02 14:34:01 +02:00
Martin HoffmannandGitHub 4d13b01022 Allow ?Sized where appropriate. (#168)
This commit adds a ?Sized trait bound to all types that exclusively wrap an
octets sequence. In the process, it also does some cleanup here and there to
improve consistency of the crate.

Specifically, it includes the following noteworthy changes:

   o  All types that wrap an octets sequence only allow unsized octets
      sequence types. They all have an associated function from_slice to
      create a reference to a value wrapping an (unsized) octets slice and
      method for_slice that converts a &self into such a reference. Where
      the latter already existed but returned a value wrapping a &[u8]
      (e.g., Dname<_> and Message<_>, the return type has changed
      accordingly.

   o  Removed CharStr::from_bytes. Use CharStr::from_octets instead.

   o  Message::from_octets now returns a new error type ShortMessage.

   o  Dropped Deref impls for Dname<_>, RelativeDname<_>.

   o  Renamed opt::KeyTag::new to opt::KeyTag::from_octets.

   o  Renamed rdata::Txt::try_from_slice to build_from_slice.
2023-02-06 13:13:44 +01:00
Martin HoffmannandGitHub a2ce078a92 The Great octseq Conversion (#160)
This commit swaps the traits and types defined in `base::octets` for their
equivalent in the `octseq` trait. These are mostly the same except that they
facilitate Generic Associated Types as stabilized in Rust 1.65. This results
in subtly changed trait bounds, though mostly these should be invisible to
the user.

One notable change is that `octseq` makes the error type of the
`OctetsBuilder` generic and uses `Infallible` for those types where
appending data will never fail (which, for most users, is all of them). It
provides methods for either case and we are mirroring these in `domain`.
While this means that converting you code to using the PR will require some
work, that work should mostly be removing unwraps – which is nice.

We’re using the opportunity to clean up a few more things that have crept
into the code over time. A list of which will be added here:

*  The range, slice, and split methods on the domain name types have
   changed. They have been merge into a single method taking ranges – except
   for those on `Dname` that require type changes. The split methods now
   take references and don’t change `self` anymore. This is somewhat
   required by the limitations imposed by the new `Octets` trait but feels
   better, anyway.

*  The `Parse`, `Compose`, and `Scan` traits have been demoted to mere
   extension traits for foreign types (primarily the built-in integers, so
   that you can do things like `u16::parse`). All other types now simply have
   methods matching the patterns. Where generics are necessary, dedicated
   traits have been added. E.g., there now are `ParseRecordData` and
   `ComposeRecordData` traits that are implemented by all record data types.

*  Composing of record data and options has been switched to a scheme where
   the size is predetermined whenever possible instead of composing the data
   and then updating the length after. Since this is not possible for record
   data that uses compressed names when compression is actually in use, the
   old scheme is still used in this particular case.
2023-01-10 12:48:41 +01:00
Martin HoffmannandGitHub cd88889557 Redesign zone file parsing. (#142)
This commit completely redesigns zone file parsing. The primary change is to
convert the scanner into a trait in order to allow multiple zone parser
implementations for different sources and purposes. A number of changes had
to be made in order to make this possible.

The commit also contains an initial implementation of a scanner that modifies
data in-place and can thus returned parsed data with only a minimal amount
of additional allocations. While working, this scanner is more a
proof-of-concept at this point to ensure that the API design is sound.

This commit is based on ideas and code proposed by @not-my-profile in #106.

This commit increases the minimal supported Rust version to 1.59.0.
2022-11-07 15:11:36 +01:00
Martin HoffmannandGitHub 4cdf3b62bf Drop AsRef<[u8]> and AsMut<[u8]> from OctetsBuilder trait bounds. (#130)
This makes it possible to impl OctetsBuilder for Cow<[u8]> and other
types that can only append at the price of explicitely requiring AsRef<[u8]>
and AsMut<[u8]> where needed. Unfortunately, this means lots of code
changes but hopefully, these should not cause too much havoc with code
using the crate.
2022-05-24 12:55:10 +02:00
Martin Hoffmann a797afd94a Implement Serde traits for all relevant types. 2021-11-08 16:30:41 +01:00
Martin Fischer 486fc7c273 doc: document feature flags on docs.rs with doc_cfg
The unstable doc_cfg feature[0] makes rustdoc generate pretty notes for
APIs that are annotated to require a certain feature flag.

This commit adds these annotations and enables the unstable feature
for docs.rs builds (which already use nightly[1]).

To build the documentation locally with this feature use:

RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --no-deps --all-features

[0]: https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html
[1]: https://docs.rs/about/builds
2021-07-19 13:53:59 +02:00
Martin Hoffmann 9c916b933f Formatting fixes. 2021-03-22 10:10:29 +01:00
Martin Hoffmann 43e22d186a Various documentation improvements. 2021-03-22 10:02:18 +01:00
Joonas Koivunen e8296d8b3e chore: redo formatting 2021-01-14 11:50:50 +02:00
Joonas Koivunen 61b7f3f121 chore: cargo fmt 2021-01-13 16:04:16 +02:00
Martin Hoffmann f10f5d339a Introduce OctetsFrom and OctetsInto. 2020-09-09 13:10:04 +02:00
Martin Hoffmann 9cdc068c0c Merge IntoOctets into OctetsBuilder. 2020-08-27 14:26:36 +02:00
Martin Hoffmann 748a4d2dc8 Merge domain-resolv into domain::resolv. 2020-08-25 17:52:10 +02:00