Skip to content

Commit cbd0a25

Browse files
committed
deny missing documentation and implement missing docs
1 parent f2382dd commit cbd0a25

File tree

8 files changed

+58
-0
lines changed

8 files changed

+58
-0
lines changed

stun-proto/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// except according to those terms.
88

99
#![deny(missing_debug_implementations)]
10+
#![deny(missing_docs)]
1011

1112
//! # stun-proto
1213
//!

stun-types/src/attribute/address.rs

+3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ impl std::fmt::Display for MappedSocketAddr {
150150
/// [`Attribute`](crate::attribute::Attribute) after an XOR operation with the [`TransactionId`]
151151
/// of a [`Message`](crate::message::Message).
152152
#[derive(Debug, Clone, PartialEq, Eq)]
153+
#[repr(transparent)]
153154
pub struct XorSocketAddr {
155+
/// The parent [`MappedSocketAddr`]
154156
pub addr: MappedSocketAddr,
155157
}
156158

@@ -178,6 +180,7 @@ impl XorSocketAddr {
178180
Ok(Self { addr })
179181
}
180182

183+
/// Returns the XOR of the `addr` with the `transaction` and the hardcoded XOR constant.
181184
pub fn xor_addr(addr: SocketAddr, transaction: TransactionId) -> SocketAddr {
182185
match addr {
183186
SocketAddr::V4(addr) => {

stun-types/src/attribute/error.rs

+17
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,37 @@ impl<'reason> ErrorCodeBuilder<'reason> {
119119
}
120120

121121
impl ErrorCode {
122+
/// Try an alternate server. The [`AlternateServer`] or [`AlternateDomain`] contains the
123+
/// location of where to forward this request.
122124
pub const TRY_ALTERNATE: u16 = 301;
125+
/// The request was malformed and could not be processed.
123126
pub const BAD_REQUEST: u16 = 400;
127+
/// The required credentials were not found or did not match.
124128
pub const UNAUTHORIZED: u16 = 401;
129+
/// Not allowed to access this resource.
125130
pub const FORBIDDEN: u16 = 403;
131+
/// An unknown comprehension required attribute was present. The [`UnknownAttributes`]
132+
/// contains the specific attribute/s.
126133
pub const UNKNOWN_ATTRIBUTE: u16 = 420;
134+
/// The allocation already exists on this server.
127135
pub const ALLOCATION_MISMATCH: u16 = 437;
136+
/// The nonce is no longer valid.
128137
pub const STALE_NONCE: u16 = 438;
138+
/// The address family (IPv4, IPv6) is not supported.
129139
pub const ADDRESS_FAMILY_NOT_SUPPORTED: u16 = 440;
140+
/// Incorrect credentials provided.
130141
pub const WRONG_CREDENTIALS: u16 = 441;
142+
/// The transport protocol (UDP, TCP) is not supported.
131143
pub const UNSUPPORTED_TRANSPORT_PROTOCOL: u16 = 442;
144+
/// The peer address family does not match the TURN allocation.
132145
pub const PEER_ADDRESS_FAMILY_MISMATCH: u16 = 443;
146+
/// This username has reached its limit of allocations currently allowed.
133147
pub const ALLOCATION_QUOTA_REACHED: u16 = 486;
148+
/// Requestor must switch ICE roles.
134149
pub const ROLE_CONFLICT: u16 = 487;
150+
/// An unspecificed error has occurred.
135151
pub const SERVER_ERROR: u16 = 500;
152+
/// The server does not have capacity to handle this request.
136153
pub const INSUFFICIENT_CAPACITY: u16 = 508;
137154

138155
/// Create a builder for creating a new [`ErrorCode`] [`Attribute`]

stun-types/src/attribute/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ impl TryFrom<&[u8]> for AttributeHeader {
292292

293293
/// A static type for an [`Attribute`]
294294
pub trait AttributeStaticType {
295+
/// The [`AttributeType`]
295296
const TYPE: AttributeType;
296297
}
297298

@@ -351,6 +352,7 @@ fn padded_attr_len(len: usize) -> usize {
351352
}
352353
}
353354

355+
/// Automatically implemented trait providing some helper functions.
354356
pub trait AttributeExt {
355357
/// The length in bytes of an attribute as stored in a [`Message`](crate::message::Message)
356358
/// including any padding and the attribute header.
@@ -363,14 +365,30 @@ impl<A: Attribute + ?Sized> AttributeExt for A {
363365
}
364366
}
365367

368+
/// Trait required when implementing writing an [`Attribute`] to a sequence of bytes
366369
pub trait AttributeWrite: Attribute {
370+
/// Write the 4 byte attribute header into the provided destination buffer returning the
371+
/// number of bytes written.
372+
///
373+
/// Panics if the destination buffer is not large enough
367374
fn write_into_unchecked(&self, dest: &mut [u8]);
375+
/// Produce a [`RawAttribute`] from this [`Attribute`]
368376
fn to_raw(&self) -> RawAttribute;
369377
}
370378

379+
/// Automatically implemented trait providing helper functionality for writing an [`Attribute`] to
380+
/// a sequence of bytes.
371381
pub trait AttributeWriteExt: AttributeWrite {
382+
/// Write the 4 byte attribute header into the provided destination buffer returning the
383+
/// number of bytes written.
384+
///
385+
/// Panics if the destination cannot hold at least 4 bytes of data.
372386
fn write_header_unchecked(&self, dest: &mut [u8]) -> usize;
387+
/// Write the 4 byte attribute header into the provided destination buffer returning the
388+
/// number of bytes written, or an error.
373389
fn write_header(&self, dest: &mut [u8]) -> Result<usize, StunWriteError>;
390+
/// Write this attribute into the provided destination buffer returning the number of bytes
391+
/// written, or an error.
374392
fn write_into(&self, dest: &mut [u8]) -> Result<usize, StunWriteError>;
375393
}
376394

stun-types/src/attribute/password_algorithm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use super::{
2020
/// The hashing algorithm for the password
2121
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2222
pub enum PasswordAlgorithmValue {
23+
/// The MD-5 hashing algorithm.
2324
MD5,
25+
/// The SHA-256 hashing algorithm.
2426
SHA256,
2527
}
2628

stun-types/src/data.rs

+2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ impl From<Box<[u8]>> for DataOwned {
8080
/// An owned or borrowed piece of data
8181
#[derive(Debug, Clone, PartialEq, Eq)]
8282
pub enum Data<'a> {
83+
/// Borrowed data.
8384
Borrowed(DataSlice<'a>),
85+
/// Owned data.
8486
Owned(DataOwned),
8587
}
8688

stun-types/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// except according to those terms.
88

99
#![deny(missing_debug_implementations)]
10+
#![deny(missing_docs)]
1011

1112
//! # stun-types
1213
//!
@@ -72,6 +73,7 @@ impl std::fmt::Display for TransportType {
7273
}
7374
}
7475

76+
/// Prelude module for traits
7577
pub mod prelude {
7678
pub use crate::attribute::{
7779
Attribute, AttributeExt, AttributeFromRaw, AttributeStaticType, AttributeWrite,

stun-types/src/message.rs

+13
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub const MAGIC_COOKIE: u32 = 0x2112A442;
9191
/// message.
9292
pub const BINDING: u16 = 0x0001;
9393

94+
/// Possible errors when parsing a STUN message.
9495
#[derive(Debug, thiserror::Error)]
9596
pub enum StunParseError {
9697
/// Not a STUN message.
@@ -263,7 +264,9 @@ impl ShortTermCredentials {
263264
#[derive(Debug, Clone, PartialEq, Eq)]
264265
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
265266
pub enum MessageIntegrityCredentials {
267+
/// Short term integrity credentials.
266268
ShortTerm(ShortTermCredentials),
269+
/// Long term integrity credentials.
267270
LongTerm(LongTermCredentials),
268271
}
269272

@@ -311,9 +314,13 @@ impl MessageIntegrityCredentials {
311314
/// - [Error][`MessageClass::Error`] class indicates that an error was produced.
312315
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
313316
pub enum MessageClass {
317+
/// A request that is expecting a response of either Success, or Error.
314318
Request,
319+
/// A request that does not expect a response.
315320
Indication,
321+
/// A success response to a previous Request.
316322
Success,
323+
/// An error response to a previous Request.
317324
Error,
318325
}
319326

@@ -614,7 +621,9 @@ impl<'a> std::fmt::Display for Message<'a> {
614621
/// The supported hashing algorithms for ensuring integrity of a [`Message`]
615622
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
616623
pub enum IntegrityAlgorithm {
624+
/// SHA-1 algorithm
617625
Sha1,
626+
/// SHA-256 algorithm
618627
Sha256,
619628
}
620629

@@ -1475,6 +1484,8 @@ impl<'a> MessageBuilder<'a> {
14751484
ret
14761485
}
14771486

1487+
/// Write this builder into the provided destination buffer returning the length in bytes that
1488+
/// has been written, or an error.
14781489
#[tracing::instrument(
14791490
name = "message_build",
14801491
level = "trace",
@@ -1503,6 +1514,8 @@ impl<'a> MessageBuilder<'a> {
15031514
Ok(offset)
15041515
}
15051516

1517+
/// The length in bytes this [`MessageBuilder`] would require to successfully construct
1518+
/// a message.
15061519
pub fn byte_len(&self) -> usize {
15071520
MessageHeader::LENGTH
15081521
+ self

0 commit comments

Comments
 (0)