Skip to content

Commit

Permalink
Remove Sized constraint from tsig module types. (#241)
Browse files Browse the repository at this point in the history
Currently the requirement of sized types means that Message<[u8]> cannot
be used in tsig operations.
  • Loading branch information
torin-carey authored Nov 13, 2023
1 parent 337d036 commit 5987386
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/tsig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Key {
}

/// Checks whether the key in the record is this key.
fn check_tsig<Octs: Octets>(
fn check_tsig<Octs: Octets + ?Sized>(
&self,
tsig: &MessageTsig<Octs>,
) -> Result<(), ValidationError> {
Expand Down Expand Up @@ -494,7 +494,7 @@ impl<K: AsRef<Key>> ClientTransaction<K> {
/// whether this record is a correct record for this transaction and if
/// it correctly signs the answer for this transaction. If any of this
/// fails, returns an error.
pub fn answer<Octs: Octets + AsMut<[u8]>>(
pub fn answer<Octs: Octets + AsMut<[u8]> + ?Sized>(
&self,
message: &mut Message<Octs>,
now: Time48,
Expand Down Expand Up @@ -569,7 +569,7 @@ impl<K: AsRef<Key>> ServerTransaction<K> {
) -> Result<Option<Self>, ServerError<K>>
where
Store: KeyStore<Key = K>,
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
SigningContext::server_request(store, message, now).map(|context| {
context.map(|context| ServerTransaction { context })
Expand Down Expand Up @@ -729,7 +729,7 @@ impl<K: AsRef<Key>> ClientSequence<K> {
now: Time48,
) -> Result<(), ValidationError>
where
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
if self.first {
self.answer_first(message, now)
Expand Down Expand Up @@ -760,7 +760,7 @@ impl<K: AsRef<Key>> ClientSequence<K> {
now: Time48,
) -> Result<(), ValidationError>
where
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
let tsig = match self.context.get_answer_tsig(message)? {
Some(some) => some,
Expand Down Expand Up @@ -796,7 +796,7 @@ impl<K: AsRef<Key>> ClientSequence<K> {
now: Time48,
) -> Result<(), ValidationError>
where
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
let tsig = match self.context.get_answer_tsig(message)? {
Some(tsig) => tsig,
Expand Down Expand Up @@ -892,7 +892,7 @@ impl<K: AsRef<Key>> ServerSequence<K> {
) -> Result<Option<Self>, ServerError<K>>
where
Store: KeyStore<Key = K>,
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
SigningContext::server_request(store, message, now).map(|context| {
context.map(|context| ServerSequence {
Expand Down Expand Up @@ -999,7 +999,7 @@ impl<K: AsRef<Key>> SigningContext<K> {
) -> Result<Option<Self>, ServerError<Store::Key>>
where
Store: KeyStore<Key = K>,
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
// 4.5 Server TSIG checks
//
Expand Down Expand Up @@ -1090,7 +1090,7 @@ impl<K: AsRef<Key>> SigningContext<K> {
message: &'a Message<Octs>,
) -> Result<Option<MessageTsig<'a, Octs>>, ValidationError>
where
Octs: Octets,
Octs: Octets + ?Sized,
{
// Extract TSIG or bail out.
let tsig = match MessageTsig::from_message(message) {
Expand Down Expand Up @@ -1127,7 +1127,7 @@ impl<K: AsRef<Key>> SigningContext<K> {
now: Time48,
) -> Result<(), ValidationError>
where
Octs: Octets,
Octs: Octets + ?Sized,
{
if message.header().rcode() == Rcode::NotAuth
&& tsig.record.data().error() == TsigRcode::BadTime
Expand Down Expand Up @@ -1293,7 +1293,7 @@ impl<K: AsRef<Key>> SigningContext<K> {
//------------ MessageTsig ---------------------------------------------------

/// The TSIG record of a message.
struct MessageTsig<'a, Octs: Octets + 'a> {
struct MessageTsig<'a, Octs: Octets + ?Sized + 'a> {
/// The actual record.
#[allow(clippy::type_complexity)]
record: Record<
Expand All @@ -1305,7 +1305,7 @@ struct MessageTsig<'a, Octs: Octets + 'a> {
start: usize,
}

impl<'a, Octs: Octets> MessageTsig<'a, Octs> {
impl<'a, Octs: Octets + ?Sized> MessageTsig<'a, Octs> {
/// Get the TSIG record from a message.
///
/// Checks that there is exactly one TSIG record in the additional
Expand Down Expand Up @@ -1583,7 +1583,7 @@ impl fmt::Display for Algorithm {

fn remove_tsig<Octs>(original_id: u16, message: &mut Message<Octs>)
where
Octs: Octets + AsMut<[u8]>,
Octs: Octets + AsMut<[u8]> + ?Sized,
{
message.header_mut().set_id(original_id);
message.remove_last_additional();
Expand Down Expand Up @@ -1640,7 +1640,7 @@ impl<K: AsRef<Key>> ServerError<K> {
builder: MessageBuilder<Target>,
) -> Result<AdditionalBuilder<Target>, PushError>
where
Octs: Octets,
Octs: Octets + ?Sized,
Target: Composer,
{
let builder = builder.start_answer(msg, Rcode::NotAuth)?;
Expand Down

0 comments on commit 5987386

Please sign in to comment.