Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SerializeOctets bounds #344

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ name = "domain"
path = "src/lib.rs"

[dependencies]
octseq = { version = "0.5.2-dev", git = "https://github.com/NLnetLabs/octseq.git", rev ="3f7797f4274af0a52e66105250ee1186ff2ab6ac", default-features = false }
octseq = { version = "0.5.2-dev", git = "https://github.com/NLnetLabs/octseq.git", branch = "remove-serialize-bounds", default-features = false }
time = { version = "0.3.1", default-features = false }

rand = { version = "0.8", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions src/base/charstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use bytes::BytesMut;
use core::{cmp, fmt, hash, mem, str};
use octseq::builder::FreezeBuilder;
#[cfg(feature = "serde")]
use octseq::serde::{DeserializeOctets, SerializeOctets};
use octseq::serde::DeserializeOctets;
use octseq::{
EmptyBuilder, FromBuilder, IntoBuilder, Octets, OctetsBuilder,
OctetsFrom, Parser, ShortBuf, Truncate,
Expand Down Expand Up @@ -594,7 +594,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized + 'a> IntoIterator for &'a CharStr<T> {
#[cfg(feature = "serde")]
impl<T> serde::Serialize for CharStr<T>
where
T: AsRef<[u8]> + SerializeOctets + ?Sized,
T: AsRef<[u8]> + ?Sized,
{
fn serialize<S: serde::Serializer>(
&self,
Expand All @@ -608,7 +608,7 @@ where
} else {
serializer.serialize_newtype_struct(
"CharStr",
&self.0.as_serialized_octets(),
&octseq::serde::AsSerializedOctets::from(&self.0),
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/base/name/absolute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use octseq::builder::{
use octseq::octets::{Octets, OctetsFrom};
use octseq::parse::Parser;
#[cfg(feature = "serde")]
use octseq::serde::{DeserializeOctets, SerializeOctets};
use octseq::serde::DeserializeOctets;
#[cfg(feature = "std")]
use std::vec::Vec;

Expand Down Expand Up @@ -980,7 +980,7 @@ impl<Octs: AsRef<[u8]>> borrow::Borrow<Name<[u8]>> for Name<Octs> {
#[cfg(feature = "serde")]
impl<Octs> serde::Serialize for Name<Octs>
where
Octs: AsRef<[u8]> + SerializeOctets + ?Sized,
Octs: AsRef<[u8]> + ?Sized,
{
fn serialize<S: serde::Serializer>(
&self,
Expand All @@ -992,7 +992,7 @@ where
} else {
serializer.serialize_newtype_struct(
"Name",
&self.0.as_serialized_octets(),
&octseq::serde::AsSerializedOctets::from(&self.0),
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/base/name/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,6 @@ impl serde::Serialize for OwnedLabel {
&self,
serializer: S,
) -> Result<S::Ok, S::Error> {
use octseq::serde::SerializeOctets;

if serializer.is_human_readable() {
serializer.serialize_newtype_struct(
"OwnedLabel",
Expand All @@ -662,7 +660,9 @@ impl serde::Serialize for OwnedLabel {
} else {
serializer.serialize_newtype_struct(
"OwnedLabel",
&self.as_label().as_slice().as_serialized_octets(),
&octseq::serde::AsSerializedOctets::from(
self.as_label().as_slice(),
),
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/base/name/relative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use octseq::builder::{
};
use octseq::octets::{Octets, OctetsFrom};
#[cfg(feature = "serde")]
use octseq::serde::{DeserializeOctets, SerializeOctets};
use octseq::serde::DeserializeOctets;
#[cfg(feature = "std")]
use std::vec::Vec;

Expand Down Expand Up @@ -781,7 +781,7 @@ where
#[cfg(feature = "serde")]
impl<Octs> serde::Serialize for RelativeName<Octs>
where
Octs: AsRef<[u8]> + SerializeOctets + ?Sized,
Octs: AsRef<[u8]> + ?Sized,
{
fn serialize<S: serde::Serializer>(
&self,
Expand All @@ -795,7 +795,7 @@ where
} else {
serializer.serialize_newtype_struct(
"RelativeName",
&self.0.as_serialized_octets(),
&octseq::serde::AsSerializedOctets::from(&self.0.as_ref()),
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/base/name/uncertain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use octseq::builder::{
EmptyBuilder, FreezeBuilder, FromBuilder, IntoBuilder,
};
#[cfg(feature = "serde")]
use octseq::serde::{DeserializeOctets, SerializeOctets};
use octseq::serde::DeserializeOctets;
#[cfg(feature = "std")]
use std::vec::Vec;

Expand Down Expand Up @@ -438,7 +438,7 @@ impl<Octets: AsRef<[u8]>> fmt::Debug for UncertainName<Octets> {
#[cfg(feature = "serde")]
impl<Octets> serde::Serialize for UncertainName<Octets>
where
Octets: AsRef<[u8]> + SerializeOctets,
Octets: AsRef<[u8]>,
{
fn serialize<S: serde::Serializer>(
&self,
Expand All @@ -452,7 +452,7 @@ where
} else {
serializer.serialize_newtype_struct(
"UncertainName",
&self.as_octets().as_serialized_octets(),
&octseq::serde::AsSerializedOctets::from(self.as_octets()),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/rdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub struct UnknownRecordData<Octs> {
serialize_with = "crate::utils::base16::serde::serialize",
deserialize_with = "crate::utils::base16::serde::deserialize",
bound(
serialize = "Octs: AsRef<[u8]> + octseq::serde::SerializeOctets",
serialize = "Octs: AsRef<[u8]>",
deserialize = "\
Octs: \
octseq::builder::FromBuilder + \
Expand Down
51 changes: 31 additions & 20 deletions src/rdata/cds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::base::cmp::CanonicalOrd;
use crate::base::iana::{DigestAlg, Rtype, SecAlg};
use crate::base::rdata::{
ComposeRecordData, LongRecordData, ParseRecordData, RecordData
ComposeRecordData, LongRecordData, ParseRecordData, RecordData,
};
use crate::base::scan::{Scan, Scanner, ScannerError};
use crate::base::wire::{Compose, Composer, Parse, ParseError};
Expand All @@ -21,9 +21,7 @@ use octseq::parse::Parser;
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(bound(
serialize = "
Octs: octseq::serde::SerializeOctets + AsRef<[u8]>
",
serialize = "Octs: AsRef<[u8]>",
deserialize = "
Octs:
octseq::builder::FromBuilder
Expand Down Expand Up @@ -57,11 +55,15 @@ impl<Octs> Cdnskey<Octs> {
algorithm: SecAlg,
public_key: Octs,
) -> Result<Self, LongRecordData>
where Octs: AsRef<[u8]> {
where
Octs: AsRef<[u8]>,
{
LongRecordData::check_len(
usize::from(
u16::COMPOSE_LEN + u8::COMPOSE_LEN + SecAlg::COMPOSE_LEN
).checked_add(public_key.as_ref().len()).expect("long key")
u16::COMPOSE_LEN + u8::COMPOSE_LEN + SecAlg::COMPOSE_LEN,
)
.checked_add(public_key.as_ref().len())
.expect("long key"),
)?;
Ok(unsafe {
Cdnskey::new_unchecked(flags, protocol, algorithm, public_key)
Expand Down Expand Up @@ -143,13 +145,16 @@ impl<Octs> Cdnskey<Octs> {
pub fn scan<S: Scanner<Octets = Octs>>(
scanner: &mut S,
) -> Result<Self, S::Error>
where Octs: AsRef<[u8]> {
where
Octs: AsRef<[u8]>,
{
Self::new(
u16::scan(scanner)?,
u8::scan(scanner)?,
SecAlg::scan(scanner)?,
scanner.convert_entry(base64::SymbolConverter::new())?,
).map_err(|err| S::Error::custom(err.as_str()))
)
.map_err(|err| S::Error::custom(err.as_str()))
}
}

Expand Down Expand Up @@ -326,9 +331,7 @@ impl<Octs: AsRef<[u8]>> fmt::Debug for Cdnskey<Octs> {
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(bound(
serialize = "
Octs: octseq::serde::SerializeOctets + AsRef<[u8]>
",
serialize = "Octs: AsRef<[u8]>",
deserialize = "
Octs:
octseq::builder::FromBuilder
Expand Down Expand Up @@ -362,11 +365,17 @@ impl<Octs> Cds<Octs> {
digest_type: DigestAlg,
digest: Octs,
) -> Result<Self, LongRecordData>
where Octs: AsRef<[u8]> {
where
Octs: AsRef<[u8]>,
{
LongRecordData::check_len(
usize::from(
u16::COMPOSE_LEN + SecAlg::COMPOSE_LEN + DigestAlg::COMPOSE_LEN
).checked_add(digest.as_ref().len()).expect("long digest")
u16::COMPOSE_LEN
+ SecAlg::COMPOSE_LEN
+ DigestAlg::COMPOSE_LEN,
)
.checked_add(digest.as_ref().len())
.expect("long digest"),
)?;
Ok(unsafe {
Cds::new_unchecked(key_tag, algorithm, digest_type, digest)
Expand Down Expand Up @@ -452,13 +461,16 @@ impl<Octs> Cds<Octs> {
pub fn scan<S: Scanner<Octets = Octs>>(
scanner: &mut S,
) -> Result<Self, S::Error>
where Octs: AsRef<[u8]> {
where
Octs: AsRef<[u8]>,
{
Self::new(
u16::scan(scanner)?,
SecAlg::scan(scanner)?,
DigestAlg::scan(scanner)?,
scanner.convert_entry(base16::SymbolConverter::new())?,
).map_err(|err| S::Error::custom(err.as_str()))
)
.map_err(|err| S::Error::custom(err.as_str()))
}
}

Expand Down Expand Up @@ -678,9 +690,8 @@ mod test {
#[test]
#[allow(clippy::redundant_closure)] // lifetimes ...
fn cds_compose_parse_scan() {
let rdata = Cds::new(
10, SecAlg::RSASHA1, DigestAlg::SHA256, b"key"
).unwrap();
let rdata =
Cds::new(10, SecAlg::RSASHA1, DigestAlg::SHA256, b"key").unwrap();
test_rdlen(&rdata);
test_compose_parse(&rdata, |parser| Cds::parse(parser));
test_scan(&["10", "RSASHA1", "2", "6b6579"], Cds::scan, &rdata);
Expand Down
22 changes: 9 additions & 13 deletions src/rdata/dnssec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use octseq::builder::{
use octseq::octets::{Octets, OctetsFrom, OctetsInto};
use octseq::parse::Parser;
#[cfg(feature = "serde")]
use octseq::serde::{DeserializeOctets, SerializeOctets};
use octseq::serde::DeserializeOctets;
#[cfg(feature = "std")]
use std::vec::Vec;
use time::{Date, Month, PrimitiveDateTime, Time};
Expand All @@ -36,9 +36,7 @@ use time::{Date, Month, PrimitiveDateTime, Time};
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(bound(
serialize = "
Octs: octseq::serde::SerializeOctets + AsRef<[u8]>
",
serialize = "Octs: AsRef<[u8]>",
deserialize = "
Octs: FromBuilder + octseq::serde::DeserializeOctets<'de>,
<Octs as FromBuilder>::Builder:
Expand Down Expand Up @@ -797,7 +795,7 @@ fn u32_from_buf(buf: &[u8]) -> u32 {
derive(serde::Serialize, serde::Deserialize),
serde(bound(
serialize = "
Octs: octseq::serde::SerializeOctets + AsRef<[u8]>,
Octs: AsRef<[u8]>,
Name: serde::Serialize,
",
deserialize = "
Expand Down Expand Up @@ -1362,7 +1360,7 @@ where
derive(serde::Serialize, serde::Deserialize),
serde(bound(
serialize = "
Octs: octseq::serde::SerializeOctets + AsRef<[u8]>,
Octs: AsRef<[u8]>,
Name: serde::Serialize,
",
deserialize = "
Expand Down Expand Up @@ -1641,9 +1639,7 @@ where
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
serde(bound(
serialize = "
Octs: octseq::serde::SerializeOctets + AsRef<[u8]>
",
serialize = "Octs: AsRef<[u8]>",
deserialize = "
Octs: FromBuilder + octseq::serde::DeserializeOctets<'de>,
<Octs as FromBuilder>::Builder:
Expand Down Expand Up @@ -2193,7 +2189,7 @@ impl<Octs: AsRef<[u8]>> fmt::Debug for RtypeBitmap<Octs> {
#[cfg(feature = "serde")]
impl<Octs> serde::Serialize for RtypeBitmap<Octs>
where
Octs: AsRef<[u8]> + SerializeOctets,
Octs: AsRef<[u8]>,
{
fn serialize<S: serde::Serializer>(
&self,
Expand Down Expand Up @@ -2224,7 +2220,7 @@ where
} else {
serializer.serialize_newtype_struct(
"RtypeBitmap",
&self.0.as_serialized_octets(),
&octseq::serde::AsSerializedOctets::from(&self.0),
)
}
}
Expand Down Expand Up @@ -2432,8 +2428,8 @@ where
let buf_len = self.buf.as_ref().len();
for src_pos in (0..buf_len).step_by(34) {
let chunk_len = (self.buf.as_ref()[src_pos + 1] as usize) + 2;
let buf = self.buf.as_mut();
buf.copy_within(src_pos..src_pos+chunk_len, dst_pos);
let buf = self.buf.as_mut();
buf.copy_within(src_pos..src_pos + chunk_len, dst_pos);
dst_pos += chunk_len;
}
self.buf.truncate(dst_pos);
Expand Down
2 changes: 1 addition & 1 deletion src/rdata/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ macro_rules! rdata_types {
feature = "serde",
serde(bound(
serialize = "
O: AsRef<[u8]> + octseq::serde::SerializeOctets,
O: AsRef<[u8]>,
N: serde::Serialize,
",
deserialize = "
Expand Down
Loading