1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
//! Error codes that are defined in [RFC 5389 -- 15.6 ERROR-CODE].
//!
//! [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
use crate::rfc5389::attributes::ErrorCode;
/// `300`: "Try Alternate".
///
/// > The client should contact an alternate server for
/// > this request. This error response MUST only be sent if the
/// > request included a USERNAME attribute and a valid MESSAGE-
/// > INTEGRITY attribute; otherwise, it MUST NOT be sent and error
/// > code 400 (Bad Request) is suggested. This error response MUST
/// > be protected with the MESSAGE-INTEGRITY attribute, and receivers
/// > MUST validate the MESSAGE-INTEGRITY of this response before
/// > redirecting themselves to an alternate server.
/// >
/// > > Note: Failure to generate and validate message integrity
/// > > for a 300 response allows an on-path attacker to falsify a
/// > > 300 response thus causing subsequent STUN messages to be
/// > > sent to a victim.
/// >
/// > [RFC 5389 -- 15.6 ERROR-CODE]
///
/// [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TryAlternate;
impl TryAlternate {
/// The codepoint of the error.
pub const CODEPOINT: u16 = 300;
}
impl From<TryAlternate> for ErrorCode {
fn from(_: TryAlternate) -> Self {
ErrorCode::new(TryAlternate::CODEPOINT, "Try Alternate".to_owned()).expect("never fails")
}
}
/// `400`: "Bad Request".
///
/// > The request was malformed. The client SHOULD NOT
/// > retry the request without modification from the previous
/// > attempt. The server may not be able to generate a valid
/// > MESSAGE-INTEGRITY for this error, so the client MUST NOT expect
/// > a valid MESSAGE-INTEGRITY attribute on this response.
/// >
/// > [RFC 5389 -- 15.6 ERROR-CODE]
///
/// [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BadRequest;
impl BadRequest {
/// The codepoint of the error.
pub const CODEPOINT: u16 = 400;
}
impl From<BadRequest> for ErrorCode {
fn from(_: BadRequest) -> Self {
ErrorCode::new(BadRequest::CODEPOINT, "Bad Request".to_owned()).expect("never fails")
}
}
/// `401`: "Unauthorized".
///
/// > The request did not contain the correct
/// > credentials to proceed. The client should retry the request
/// > with proper credentials.
/// >
/// > [RFC 5389 -- 15.6 ERROR-CODE]
///
/// [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Unauthorized;
impl Unauthorized {
/// The codepoint of the error.
pub const CODEPOINT: u16 = 401;
}
impl From<Unauthorized> for ErrorCode {
fn from(_: Unauthorized) -> Self {
ErrorCode::new(Unauthorized::CODEPOINT, "Unauthorized".to_owned()).expect("never fails")
}
}
/// `420`: "Unknown Attribute".
///
/// > The server received a STUN packet containing
/// > a comprehension-required attribute that it did not understand.
/// > The server MUST put this unknown attribute in the UNKNOWN-
/// > ATTRIBUTE attribute of its error response.
/// >
/// > [RFC 5389 -- 15.6 ERROR-CODE]
///
/// [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct UnknownAttribute;
impl UnknownAttribute {
/// The codepoint of the error.
pub const CODEPOINT: u16 = 420;
}
impl From<UnknownAttribute> for ErrorCode {
fn from(_: UnknownAttribute) -> Self {
ErrorCode::new(UnknownAttribute::CODEPOINT, "Unknown Attribute".to_owned())
.expect("never fails")
}
}
/// `438`: "Stale Nonce".
///
/// > The NONCE used by the client was no longer valid.
/// > The client should retry, using the NONCE provided in the
/// > response.
/// >
/// > [RFC 5389 -- 15.6 ERROR-CODE]
///
/// [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StaleNonce;
impl StaleNonce {
/// The codepoint of the error.
pub const CODEPOINT: u16 = 438;
}
impl From<StaleNonce> for ErrorCode {
fn from(_: StaleNonce) -> Self {
ErrorCode::new(StaleNonce::CODEPOINT, "Stale Nonce".to_owned()).expect("never fails")
}
}
/// `500`: "Server Error".
///
/// > The server has suffered a temporary error. The
/// > client should try again.
/// >
/// > [RFC 5389 -- 15.6 ERROR-CODE]
///
/// [RFC 5389 -- 15.6 ERROR-CODE]: https://tools.ietf.org/html/rfc5389#section-15.6
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ServerError;
impl ServerError {
/// The codepoint of the error.
pub const CODEPOINT: u16 = 500;
}
impl From<ServerError> for ErrorCode {
fn from(_: ServerError) -> Self {
ErrorCode::new(ServerError::CODEPOINT, "Server Error".to_owned()).expect("never fails")
}
}