Skip to content

Commit

Permalink
proto: inline trivial constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Dec 21, 2024
1 parent 506e744 commit 8a488f2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions quinn-proto/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,23 +203,20 @@ pub(crate) struct IncomingToken {
}

impl IncomingToken {
/// Construct for an `Incoming` which is not validated by a token
fn unvalidated(header: &InitialHeader) -> Self {
Self {
retry_src_cid: None,
orig_dst_cid: header.dst_cid,
}
}

/// Construct for an `Incoming` given the first packet header, or error if the connection
/// cannot be established
pub(crate) fn from_header(
header: &InitialHeader,
server_config: &ServerConfig,
remote_address: SocketAddr,
) -> Result<Self, InvalidRetryTokenError> {
let unvalidated = Self {
retry_src_cid: None,
orig_dst_cid: header.dst_cid,
};

if header.token.is_empty() {
return Ok(Self::unvalidated(header));
return Ok(unvalidated);
}

RetryToken::from_bytes(
Expand All @@ -230,7 +227,7 @@ impl IncomingToken {
)
.and_then(|token| token.validate(header, server_config))
.or_else(|e| match e {
ValidationError::Unusable => Ok(Self::unvalidated(header)),
ValidationError::Unusable => Ok(unvalidated),
ValidationError::InvalidRetry => Err(InvalidRetryTokenError),
})
}
Expand Down

0 comments on commit 8a488f2

Please sign in to comment.