1#![allow(dead_code)]
2
3use std::io;
4use std::net;
5use std::net::SocketAddr;
6use std::num::ParseIntError;
7use std::string::FromUtf8Error;
8use std::time::SystemTimeError;
9use thiserror::Error;
10
11pub type Result<T> = std::result::Result<T, Error>;
12
13#[derive(Error, Debug, PartialEq)]
14#[non_exhaustive]
15pub enum Error {
16 #[error("buffer: full")]
17 ErrBufferFull,
18 #[error("buffer: closed")]
19 ErrBufferClosed,
20 #[error("buffer: short")]
21 ErrBufferShort,
22 #[error("packet too big")]
23 ErrPacketTooBig,
24 #[error("i/o timeout")]
25 ErrTimeout,
26 #[error("udp: listener closed")]
27 ErrClosedListener,
28 #[error("udp: listen queue exceeded")]
29 ErrListenQueueExceeded,
30 #[error("udp: listener accept ch closed")]
31 ErrClosedListenerAcceptCh,
32 #[error("obs cannot be nil")]
33 ErrObsCannotBeNil,
34 #[error("se of closed network connection")]
35 ErrUseClosedNetworkConn,
36 #[error("addr is not a net.UDPAddr")]
37 ErrAddrNotUdpAddr,
38 #[error("something went wrong with locAddr")]
39 ErrLocAddr,
40 #[error("already closed")]
41 ErrAlreadyClosed,
42 #[error("no remAddr defined")]
43 ErrNoRemAddr,
44 #[error("address already in use")]
45 ErrAddressAlreadyInUse,
46 #[error("no such UDPConn")]
47 ErrNoSuchUdpConn,
48 #[error("cannot remove unspecified IP by the specified IP")]
49 ErrCannotRemoveUnspecifiedIp,
50 #[error("no address assigned")]
51 ErrNoAddressAssigned,
52 #[error("1:1 NAT requires more than one mapping")]
53 ErrNatRequriesMapping,
54 #[error("length mismtach between mappedIPs and localIPs")]
55 ErrMismatchLengthIp,
56 #[error("non-udp translation is not supported yet")]
57 ErrNonUdpTranslationNotSupported,
58 #[error("no associated local address")]
59 ErrNoAssociatedLocalAddress,
60 #[error("no NAT binding found")]
61 ErrNoNatBindingFound,
62 #[error("has no permission")]
63 ErrHasNoPermission,
64 #[error("host name must not be empty")]
65 ErrHostnameEmpty,
66 #[error("failed to parse IP address")]
67 ErrFailedToParseIpaddr,
68 #[error("no interface is available")]
69 ErrNoInterface,
70 #[error("not found")]
71 ErrNotFound,
72 #[error("unexpected network")]
73 ErrUnexpectedNetwork,
74 #[error("can't assign requested address")]
75 ErrCantAssignRequestedAddr,
76 #[error("unknown network")]
77 ErrUnknownNetwork,
78 #[error("no router linked")]
79 ErrNoRouterLinked,
80 #[error("invalid port number")]
81 ErrInvalidPortNumber,
82 #[error("unexpected type-switch failure")]
83 ErrUnexpectedTypeSwitchFailure,
84 #[error("bind failed")]
85 ErrBindFailed,
86 #[error("end port is less than the start")]
87 ErrEndPortLessThanStart,
88 #[error("port space exhausted")]
89 ErrPortSpaceExhausted,
90 #[error("vnet is not enabled")]
91 ErrVnetDisabled,
92 #[error("invalid local IP in static_ips")]
93 ErrInvalidLocalIpInStaticIps,
94 #[error("mapped in static_ips is beyond subnet")]
95 ErrLocalIpBeyondStaticIpsSubset,
96 #[error("all static_ips must have associated local IPs")]
97 ErrLocalIpNoStaticsIpsAssociated,
98 #[error("router already started")]
99 ErrRouterAlreadyStarted,
100 #[error("router already stopped")]
101 ErrRouterAlreadyStopped,
102 #[error("static IP is beyond subnet")]
103 ErrStaticIpIsBeyondSubnet,
104 #[error("address space exhausted")]
105 ErrAddressSpaceExhausted,
106 #[error("no IP address is assigned for eth0")]
107 ErrNoIpaddrEth0,
108 #[error("Invalid mask")]
109 ErrInvalidMask,
110
111 #[error("tls handshake is in progress")]
113 HandshakeInProgress,
114 #[error("context is not supported for export_keying_material")]
115 ContextUnsupported,
116 #[error("export_keying_material can not be used with a reserved label")]
117 ReservedExportKeyingMaterial,
118 #[error("no cipher suite for export_keying_material")]
119 CipherSuiteUnset,
120 #[error("export_keying_material hash: {0}")]
121 Hash(String),
122 #[error("mutex poison: {0}")]
123 PoisonError(String),
124
125 #[error("Wrong marshal size")]
128 WrongMarshalSize,
129 #[error("Invalid total lost count")]
132 InvalidTotalLost,
133 #[error("Invalid header")]
135 InvalidHeader,
136 #[error("Empty compound packet")]
138 EmptyCompound,
139 #[error("First packet in compound must be SR or RR")]
142 BadFirstPacket,
143 #[error("Compound missing SourceDescription with CNAME")]
145 MissingCname,
146 #[error("Feedback packet seen before CNAME")]
148 PacketBeforeCname,
149 #[error("Too many reports")]
151 TooManyReports,
152 #[error("Too many chunks")]
154 TooManyChunks,
155 #[error("too many sources")]
157 TooManySources,
158 #[error("Packet too short to be read")]
160 PacketTooShort,
161 #[error("Buffer too short to be written")]
163 BufferTooShort,
164 #[error("Wrong packet type")]
166 WrongType,
167 #[error("SDES must be < 255 octets long")]
169 SdesTextTooLong,
170 #[error("SDES item missing type")]
172 SdesMissingType,
173 #[error("Reason must be < 255 octets long")]
175 ReasonTooLong,
176 #[error("Invalid packet version")]
178 BadVersion,
179 #[error("Invalid padding value")]
181 WrongPadding,
182 #[error("Wrong feedback message type")]
184 WrongFeedbackType,
185 #[error("Wrong payload type")]
187 WrongPayloadType,
188 #[error("Header length is too small")]
190 HeaderTooSmall,
191 #[error("Media SSRC must be 0")]
193 SsrcMustBeZero,
194 #[error("Missing REMB identifier")]
196 MissingRembIdentifier,
197 #[error("SSRC num and length do not match")]
199 SsrcNumAndLengthMismatch,
200 #[error("Invalid size or startIndex")]
202 InvalidSizeOrStartIndex,
203 #[error("Delta exceed limit")]
205 DeltaExceedLimit,
206 #[error("Packet status chunk must be 2 bytes")]
208 PacketStatusChunkLength,
209 #[error("Invalid bitrate")]
210 InvalidBitrate,
211 #[error("Wrong chunk type")]
212 WrongChunkType,
213 #[error("Struct contains unexpected member type")]
214 BadStructMemberType,
215 #[error("Cannot read into non-pointer")]
216 BadReadParameter,
217
218 #[error("RTP header size insufficient")]
220 ErrHeaderSizeInsufficient,
221 #[error("RTP header size insufficient for extension")]
222 ErrHeaderSizeInsufficientForExtension,
223 #[error("buffer too small")]
224 ErrBufferTooSmall,
225 #[error("extension not enabled")]
226 ErrHeaderExtensionsNotEnabled,
227 #[error("extension not found")]
228 ErrHeaderExtensionNotFound,
229
230 #[error("header extension id must be between 1 and 14 for RFC 5285 extensions")]
231 ErrRfc8285oneByteHeaderIdrange,
232 #[error("header extension payload must be 16bytes or less for RFC 5285 one byte extensions")]
233 ErrRfc8285oneByteHeaderSize,
234
235 #[error("header extension id must be between 1 and 255 for RFC 5285 extensions")]
236 ErrRfc8285twoByteHeaderIdrange,
237 #[error("header extension payload must be 255bytes or less for RFC 5285 two byte extensions")]
238 ErrRfc8285twoByteHeaderSize,
239
240 #[error("header extension id must be 0 for none RFC 5285 extensions")]
241 ErrRfc3550headerIdrange,
242
243 #[error("packet is not large enough")]
244 ErrShortPacket,
245 #[error("invalid nil packet")]
246 ErrNilPacket,
247 #[error("too many PDiff")]
248 ErrTooManyPDiff,
249 #[error("too many spatial layers")]
250 ErrTooManySpatialLayers,
251 #[error("NALU Type is unhandled")]
252 ErrUnhandledNaluType,
253
254 #[error("corrupted h265 packet")]
255 ErrH265CorruptedPacket,
256 #[error("invalid h265 packet type")]
257 ErrInvalidH265PacketType,
258
259 #[error("payload is too small for OBU extension header")]
260 ErrPayloadTooSmallForObuExtensionHeader,
261 #[error("payload is too small for OBU payload size")]
262 ErrPayloadTooSmallForObuPayloadSize,
263
264 #[error("extension_payload must be in 32-bit words")]
265 HeaderExtensionPayloadNot32BitWords,
266 #[error("audio level overflow")]
267 AudioLevelOverflow,
268 #[error("payload is not large enough")]
269 PayloadIsNotLargeEnough,
270 #[error("STAP-A declared size({0}) is larger than buffer({1})")]
271 StapASizeLargerThanBuffer(usize, usize),
272 #[error("nalu type {0} is currently not handled")]
273 NaluTypeIsNotHandled(u8),
274
275 #[error("duplicated packet")]
277 ErrDuplicated,
278 #[error("SRTP master key is not long enough")]
279 ErrShortSrtpMasterKey,
280 #[error("SRTP master salt is not long enough")]
281 ErrShortSrtpMasterSalt,
282 #[error("no such SRTP Profile")]
283 ErrNoSuchSrtpProfile,
284 #[error("indexOverKdr > 0 is not supported yet")]
285 ErrNonZeroKdrNotSupported,
286 #[error("exporter called with wrong label")]
287 ErrExporterWrongLabel,
288 #[error("no config provided")]
289 ErrNoConfig,
290 #[error("no conn provided")]
291 ErrNoConn,
292 #[error("failed to verify auth tag")]
293 ErrFailedToVerifyAuthTag,
294 #[error("packet is too short to be rtcp packet")]
295 ErrTooShortRtcp,
296 #[error("payload differs")]
297 ErrPayloadDiffers,
298 #[error("started channel used incorrectly, should only be closed")]
299 ErrStartedChannelUsedIncorrectly,
300 #[error("stream has not been inited, unable to close")]
301 ErrStreamNotInited,
302 #[error("stream is already closed")]
303 ErrStreamAlreadyClosed,
304 #[error("stream is already inited")]
305 ErrStreamAlreadyInited,
306 #[error("failed to cast child")]
307 ErrFailedTypeAssertion,
308
309 #[error("index_over_kdr > 0 is not supported yet")]
310 UnsupportedIndexOverKdr,
311 #[error("SRTP Master Key must be len {0}, got {1}")]
312 SrtpMasterKeyLength(usize, usize),
313 #[error("SRTP Salt must be len {0}, got {1}")]
314 SrtpSaltLength(usize, usize),
315 #[error("SyntaxError: {0}")]
316 ExtMapParse(String),
317 #[error("ssrc {0} not exist in srtp_ssrc_state")]
318 SsrcMissingFromSrtp(u32),
319 #[error("srtp ssrc={0} index={1}: duplicated")]
320 SrtpSsrcDuplicated(u32, u16),
321 #[error("srtcp ssrc={0} index={1}: duplicated")]
322 SrtcpSsrcDuplicated(u32, usize),
323 #[error("ssrc {0} not exist in srtcp_ssrc_state")]
324 SsrcMissingFromSrtcp(u32),
325 #[error("Stream with ssrc {0} exists")]
326 StreamWithSsrcExists(u32),
327 #[error("Session RTP/RTCP type must be same as input buffer")]
328 SessionRtpRtcpTypeMismatch,
329 #[error("Session EOF")]
330 SessionEof,
331 #[error("too short SRTP packet: only {0} bytes, expected > {1} bytes")]
332 SrtpTooSmall(usize, usize),
333 #[error("too short SRTCP packet: only {0} bytes, expected > {1} bytes")]
334 SrtcpTooSmall(usize, usize),
335 #[error("failed to verify rtp auth tag")]
336 RtpFailedToVerifyAuthTag,
337 #[error("failed to verify rtcp auth tag")]
338 RtcpFailedToVerifyAuthTag,
339 #[error("SessionSRTP has been closed")]
340 SessionSrtpAlreadyClosed,
341 #[error("this stream is not a RTPStream")]
342 InvalidRtpStream,
343 #[error("this stream is not a RTCPStream")]
344 InvalidRtcpStream,
345
346 #[error("attribute not found")]
348 ErrAttributeNotFound,
349 #[error("transaction is stopped")]
350 ErrTransactionStopped,
351 #[error("transaction not exists")]
352 ErrTransactionNotExists,
353 #[error("transaction exists with same id")]
354 ErrTransactionExists,
355 #[error("agent is closed")]
356 ErrAgentClosed,
357 #[error("transaction is timed out")]
358 ErrTransactionTimeOut,
359 #[error("no default reason for ErrorCode")]
360 ErrNoDefaultReason,
361 #[error("unexpected EOF")]
362 ErrUnexpectedEof,
363 #[error("attribute size is invalid")]
364 ErrAttributeSizeInvalid,
365 #[error("attribute size overflow")]
366 ErrAttributeSizeOverflow,
367 #[error("attempt to decode to nil message")]
368 ErrDecodeToNil,
369 #[error("unexpected EOF: not enough bytes to read header")]
370 ErrUnexpectedHeaderEof,
371 #[error("integrity check failed")]
372 ErrIntegrityMismatch,
373 #[error("fingerprint check failed")]
374 ErrFingerprintMismatch,
375 #[error("FINGERPRINT before MESSAGE-INTEGRITY attribute")]
376 ErrFingerprintBeforeIntegrity,
377 #[error("bad UNKNOWN-ATTRIBUTES size")]
378 ErrBadUnknownAttrsSize,
379 #[error("invalid length of IP value")]
380 ErrBadIpLength,
381 #[error("no connection provided")]
382 ErrNoConnection,
383 #[error("client is closed")]
384 ErrClientClosed,
385 #[error("no agent is set")]
386 ErrNoAgent,
387 #[error("collector is closed")]
388 ErrCollectorClosed,
389 #[error("unsupported network")]
390 ErrUnsupportedNetwork,
391 #[error("invalid url")]
392 ErrInvalidUrl,
393 #[error("unknown scheme type")]
394 ErrSchemeType,
395 #[error("invalid hostname")]
396 ErrHost,
397
398 #[error("turn: RelayAddress must be valid IP to use RelayAddressGeneratorStatic")]
400 ErrRelayAddressInvalid,
401 #[error("turn: PacketConnConfigs and ConnConfigs are empty, unable to proceed")]
402 ErrNoAvailableConns,
403 #[error("turn: PacketConnConfig must have a non-nil Conn")]
404 ErrConnUnset,
405 #[error("turn: ListenerConfig must have a non-nil Listener")]
406 ErrListenerUnset,
407 #[error("turn: RelayAddressGenerator has invalid ListeningAddress")]
408 ErrListeningAddressInvalid,
409 #[error("turn: RelayAddressGenerator in RelayConfig is unset")]
410 ErrRelayAddressGeneratorUnset,
411 #[error("turn: max retries exceeded")]
412 ErrMaxRetriesExceeded,
413 #[error("turn: MaxPort must be not 0")]
414 ErrMaxPortNotZero,
415 #[error("turn: MaxPort must be not 0")]
416 ErrMinPortNotZero,
417 #[error("turn: MaxPort less than MinPort")]
418 ErrMaxPortLessThanMinPort,
419 #[error("turn: relay_conn cannot not be nil")]
420 ErrNilConn,
421 #[error("turn: TODO")]
422 ErrTodo,
423 #[error("turn: already listening")]
424 ErrAlreadyListening,
425 #[error("turn: Server failed to close")]
426 ErrFailedToClose,
427 #[error("turn: failed to retransmit transaction")]
428 ErrFailedToRetransmitTransaction,
429 #[error("all retransmissions failed")]
430 ErrAllRetransmissionsFailed,
431 #[error("no binding found for channel")]
432 ErrChannelBindNotFound,
433 #[error("STUN server address is not set for the client")]
434 ErrStunserverAddressNotSet,
435 #[error("only one Allocate() caller is allowed")]
436 ErrOneAllocateOnly,
437 #[error("already allocated")]
438 ErrAlreadyAllocated,
439 #[error("non-STUN message from STUN server")]
440 ErrNonStunmessage,
441 #[error("failed to decode STUN message")]
442 ErrFailedToDecodeStun,
443 #[error("unexpected STUN request message")]
444 ErrUnexpectedStunrequestMessage,
445 #[error("channel number not in [0x4000, 0x7FFF]")]
446 ErrInvalidChannelNumber,
447 #[error("channelData length != len(Data)")]
448 ErrBadChannelDataLength,
449 #[error("invalid value for requested family attribute")]
450 ErrInvalidRequestedFamilyValue,
451 #[error("fake error")]
452 ErrFakeErr,
453 #[error("use of closed network connection")]
454 ErrClosed,
455 #[error("addr is not a net.UDPAddr")]
456 ErrUdpaddrCast,
457 #[error("try-lock is already locked")]
458 ErrDoubleLock,
459 #[error("transaction closed")]
460 ErrTransactionClosed,
461 #[error("wait_for_result called on non-result transaction")]
462 ErrWaitForResultOnNonResultTransaction,
463 #[error("failed to build refresh request")]
464 ErrFailedToBuildRefreshRequest,
465 #[error("failed to refresh allocation")]
466 ErrFailedToRefreshAllocation,
467 #[error("failed to get lifetime from refresh response")]
468 ErrFailedToGetLifetime,
469 #[error("too short buffer")]
470 ErrShortBuffer,
471 #[error("unexpected response type")]
472 ErrUnexpectedResponse,
473 #[error("AllocatePacketConn must be set")]
474 ErrAllocatePacketConnMustBeSet,
475 #[error("AllocateConn must be set")]
476 ErrAllocateConnMustBeSet,
477 #[error("LeveledLogger must be set")]
478 ErrLeveledLoggerMustBeSet,
479 #[error("you cannot use the same channel number with different peer")]
480 ErrSameChannelDifferentPeer,
481 #[error("allocations must not be created with nil FivTuple")]
482 ErrNilFiveTuple,
483 #[error("allocations must not be created with nil FiveTuple.src_addr")]
484 ErrNilFiveTupleSrcAddr,
485 #[error("allocations must not be created with nil FiveTuple.dst_addr")]
486 ErrNilFiveTupleDstAddr,
487 #[error("allocations must not be created with nil turnSocket")]
488 ErrNilTurnSocket,
489 #[error("allocations must not be created with a lifetime of 0")]
490 ErrLifetimeZero,
491 #[error("allocation attempt created with duplicate FiveTuple")]
492 ErrDupeFiveTuple,
493 #[error("failed to cast net.Addr to *net.UDPAddr")]
494 ErrFailedToCastUdpaddr,
495 #[error("failed to generate nonce")]
496 ErrFailedToGenerateNonce,
497 #[error("failed to send error message")]
498 ErrFailedToSendError,
499 #[error("duplicated Nonce generated, discarding request")]
500 ErrDuplicatedNonce,
501 #[error("no such user exists")]
502 ErrNoSuchUser,
503 #[error("unexpected class")]
504 ErrUnexpectedClass,
505 #[error("unexpected method")]
506 ErrUnexpectedMethod,
507 #[error("failed to handle")]
508 ErrFailedToHandle,
509 #[error("unhandled STUN packet")]
510 ErrUnhandledStunpacket,
511 #[error("unable to handle ChannelData")]
512 ErrUnableToHandleChannelData,
513 #[error("failed to create stun message from packet")]
514 ErrFailedToCreateStunpacket,
515 #[error("failed to create channel data from packet")]
516 ErrFailedToCreateChannelData,
517 #[error("relay already allocated for 5-TUPLE")]
518 ErrRelayAlreadyAllocatedForFiveTuple,
519 #[error("RequestedTransport must be UDP")]
520 ErrRequestedTransportMustBeUdp,
521 #[error("no support for DONT-FRAGMENT")]
522 ErrNoDontFragmentSupport,
523 #[error("Request must not contain RESERVATION-TOKEN and EVEN-PORT")]
524 ErrRequestWithReservationTokenAndEvenPort,
525 #[error("no allocation found")]
526 ErrNoAllocationFound,
527 #[error("unable to handle send-indication, no permission added")]
528 ErrNoPermission,
529 #[error("packet write smaller than packet")]
530 ErrShortWrite,
531 #[error("no such channel bind")]
532 ErrNoSuchChannelBind,
533 #[error("failed writing to socket")]
534 ErrFailedWriteSocket,
535
536 #[error("Unknown type")]
539 ErrUnknownType,
540
541 #[error("queries not supported in stun address")]
543 ErrStunQuery,
544
545 #[error("invalid query")]
547 ErrInvalidQuery,
548
549 #[error("url parse: invalid port number")]
551 ErrPort,
552
553 #[error("local username fragment is less than 24 bits long")]
556 ErrLocalUfragInsufficientBits,
557
558 #[error("local password is less than 128 bits long")]
561 ErrLocalPwdInsufficientBits,
562
563 #[error("invalid transport protocol type")]
565 ErrProtoType,
566
567 #[error("no candidate pairs available")]
569 ErrNoCandidatePairs,
570
571 #[error("connecting canceled by caller")]
573 ErrCanceledByCaller,
574
575 #[error("attempted to start agent twice")]
577 ErrMultipleStart,
578
579 #[error("remote ufrag is empty")]
581 ErrRemoteUfragEmpty,
582
583 #[error("remote pwd is empty")]
585 ErrRemotePwdEmpty,
586
587 #[error("no on_candidate provided")]
589 ErrNoOnCandidateHandler,
590
591 #[error("attempting to gather candidates during gathering state")]
593 ErrMultipleGatherAttempted,
594
595 #[error("username is empty")]
597 ErrUsernameEmpty,
598
599 #[error("password is empty")]
601 ErrPasswordEmpty,
602
603 #[error("failed to parse address")]
605 ErrAddressParseFailed,
606
607 #[error("lite agents must only use host candidates")]
609 ErrLiteUsingNonHostCandidates,
610
611 #[error("lite support only")]
613 ErrLiteSupportOnly,
614
615 #[error("agent does not need URL with selected candidate types")]
617 ErrUselessUrlsProvided,
618
619 #[error("unsupported 1:1 NAT IP candidate type")]
621 ErrUnsupportedNat1to1IpCandidateType,
622
623 #[error("invalid 1:1 NAT IP mapping")]
625 ErrInvalidNat1to1IpMapping,
626
627 #[error("external mapped IP not found")]
629 ErrExternalMappedIpNotFound,
630
631 #[error("mDNS gathering cannot be used with 1:1 NAT IP mapping for host candidate")]
634 ErrMulticastDnsWithNat1to1IpMapping,
635
636 #[error("1:1 NAT IP mapping for host candidate ineffective")]
639 ErrIneffectiveNat1to1IpMappingHost,
640
641 #[error("1:1 NAT IP mapping for srflx candidate ineffective")]
644 ErrIneffectiveNat1to1IpMappingSrflx,
645
646 #[error("invalid mDNS HostName, must end with .local and can only contain a single '.'")]
648 ErrInvalidMulticastDnshostName,
649
650 #[error("mdns is not supported")]
652 ErrMulticastDnsNotSupported,
653
654 #[error("ICE Agent can not be restarted when gathering")]
656 ErrRestartWhenGathering,
657
658 #[error("run was canceled by done")]
660 ErrRunCanceled,
661
662 #[error("TCPMux is not initialized")]
664 ErrTcpMuxNotInitialized,
665
666 #[error("conn with same remote addr already exists")]
668 ErrTcpRemoteAddrAlreadyExists,
669
670 #[error("failed to send packet")]
671 ErrSendPacket,
672 #[error("attribute not long enough to be ICE candidate")]
673 ErrAttributeTooShortIceCandidate,
674 #[error("could not parse component")]
675 ErrParseComponent,
676 #[error("could not parse priority")]
677 ErrParsePriority,
678 #[error("could not parse port")]
679 ErrParsePort,
680 #[error("could not parse related addresses")]
681 ErrParseRelatedAddr,
682 #[error("could not parse type")]
683 ErrParseType,
684 #[error("unknown candidate type")]
685 ErrUnknownCandidateType,
686 #[error("failed to get XOR-MAPPED-ADDRESS response")]
687 ErrGetXorMappedAddrResponse,
688 #[error("connection with same remote address already exists")]
689 ErrConnectionAddrAlreadyExist,
690 #[error("error reading streaming packet")]
691 ErrReadingStreamingPacket,
692 #[error("error writing to")]
693 ErrWriting,
694 #[error("error closing connection")]
695 ErrClosingConnection,
696 #[error("unable to determine networkType")]
697 ErrDetermineNetworkType,
698 #[error("missing protocol scheme")]
699 ErrMissingProtocolScheme,
700 #[error("too many colons in address")]
701 ErrTooManyColonsAddr,
702 #[error("unexpected error trying to read")]
703 ErrRead,
704 #[error("unknown role")]
705 ErrUnknownRole,
706 #[error("username mismatch")]
707 ErrMismatchUsername,
708 #[error("the ICE conn can't write STUN messages")]
709 ErrIceWriteStunMessage,
710 #[error("url parse: relative URL without a base")]
711 ErrUrlParse,
712 #[error("Candidate IP could not be found")]
713 ErrCandidateIpNotFound,
714
715 #[error("conn is closed")]
717 ErrConnClosed,
718 #[error("read/write timeout")]
719 ErrDeadlineExceeded,
720 #[error("context is not supported for export_keying_material")]
721 ErrContextUnsupported,
722 #[error("packet is too short")]
723 ErrDtlspacketInvalidLength,
724 #[error("handshake is in progress")]
725 ErrHandshakeInProgress,
726 #[error("invalid content type")]
727 ErrInvalidContentType,
728 #[error("invalid mac")]
729 ErrInvalidMac,
730 #[error("packet length and declared length do not match")]
731 ErrInvalidPacketLength,
732 #[error("export_keying_material can not be used with a reserved label")]
733 ErrReservedExportKeyingMaterial,
734 #[error("client sent certificate verify but we have no certificate to verify")]
735 ErrCertificateVerifyNoCertificate,
736 #[error("client+server do not support any shared cipher suites")]
737 ErrCipherSuiteNoIntersection,
738 #[error("server hello can not be created without a cipher suite")]
739 ErrCipherSuiteUnset,
740 #[error("client sent certificate but did not verify it")]
741 ErrClientCertificateNotVerified,
742 #[error("server required client verification, but got none")]
743 ErrClientCertificateRequired,
744 #[error("server responded with SRTP Profile we do not support")]
745 ErrClientNoMatchingSrtpProfile,
746 #[error("client required Extended Master Secret extension, but server does not support it")]
747 ErrClientRequiredButNoServerEms,
748 #[error("server hello can not be created without a compression method")]
749 ErrCompressionMethodUnset,
750 #[error("client+server cookie does not match")]
751 ErrCookieMismatch,
752 #[error("cookie must not be longer then 255 bytes")]
753 ErrCookieTooLong,
754 #[error("PSK Identity Hint provided but PSK is nil")]
755 ErrIdentityNoPsk,
756 #[error("no certificate provided")]
757 ErrInvalidCertificate,
758 #[error("cipher spec invalid")]
759 ErrInvalidCipherSpec,
760 #[error("invalid or unknown cipher suite")]
761 ErrInvalidCipherSuite,
762 #[error("unable to determine if ClientKeyExchange is a public key or PSK Identity")]
763 ErrInvalidClientKeyExchange,
764 #[error("invalid or unknown compression method")]
765 ErrInvalidCompressionMethod,
766 #[error("ECDSA signature contained zero or negative values")]
767 ErrInvalidEcdsasignature,
768 #[error("invalid or unknown elliptic curve type")]
769 ErrInvalidEllipticCurveType,
770 #[error("invalid extension type")]
771 ErrInvalidExtensionType,
772 #[error("invalid hash algorithm")]
773 ErrInvalidHashAlgorithm,
774 #[error("invalid named curve")]
775 ErrInvalidNamedCurve,
776 #[error("invalid private key type")]
777 ErrInvalidPrivateKey,
778 #[error("named curve and private key type does not match")]
779 ErrNamedCurveAndPrivateKeyMismatch,
780 #[error("invalid server name format")]
781 ErrInvalidSniFormat,
782 #[error("invalid signature algorithm")]
783 ErrInvalidSignatureAlgorithm,
784 #[error("expected and actual key signature do not match")]
785 ErrKeySignatureMismatch,
786 #[error("Conn can not be created with a nil nextConn")]
787 ErrNilNextConn,
788 #[error("connection can not be created, no CipherSuites satisfy this Config")]
789 ErrNoAvailableCipherSuites,
790 #[error("connection can not be created, no SignatureScheme satisfy this Config")]
791 ErrNoAvailableSignatureSchemes,
792 #[error("no certificates configured")]
793 ErrNoCertificates,
794 #[error("no config provided")]
795 ErrNoConfigProvided,
796 #[error("client requested zero or more elliptic curves that are not supported by the server")]
797 ErrNoSupportedEllipticCurves,
798 #[error("unsupported protocol version")]
799 ErrUnsupportedProtocolVersion,
800 #[error("Certificate and PSK provided")]
801 ErrPskAndCertificate,
802 #[error("PSK and PSK Identity Hint must both be set for client")]
803 ErrPskAndIdentityMustBeSetForClient,
804 #[error("SRTP support was requested but server did not respond with use_srtp extension")]
805 ErrRequestedButNoSrtpExtension,
806 #[error("Certificate is mandatory for server")]
807 ErrServerMustHaveCertificate,
808 #[error("client requested SRTP but we have no matching profiles")]
809 ErrServerNoMatchingSrtpProfile,
810 #[error(
811 "server requires the Extended Master Secret extension, but the client does not support it"
812 )]
813 ErrServerRequiredButNoClientEms,
814 #[error("expected and actual verify data does not match")]
815 ErrVerifyDataMismatch,
816 #[error("handshake message unset, unable to marshal")]
817 ErrHandshakeMessageUnset,
818 #[error("invalid flight number")]
819 ErrInvalidFlight,
820 #[error("unable to generate key signature, unimplemented")]
821 ErrKeySignatureGenerateUnimplemented,
822 #[error("unable to verify key signature, unimplemented")]
823 ErrKeySignatureVerifyUnimplemented,
824 #[error("data length and declared length do not match")]
825 ErrLengthMismatch,
826 #[error("buffer not long enough to contain nonce")]
827 ErrNotEnoughRoomForNonce,
828 #[error("feature has not been implemented yet")]
829 ErrNotImplemented,
830 #[error("sequence number overflow")]
831 ErrSequenceNumberOverflow,
832 #[error("unable to marshal fragmented handshakes")]
833 ErrUnableToMarshalFragmented,
834 #[error("invalid state machine transition")]
835 ErrInvalidFsmTransition,
836 #[error("ApplicationData with epoch of 0")]
837 ErrApplicationDataEpochZero,
838 #[error("unhandled contentType")]
839 ErrUnhandledContextType,
840 #[error("context canceled")]
841 ErrContextCanceled,
842 #[error("empty fragment")]
843 ErrEmptyFragment,
844 #[error("Alert is Fatal or Close Notify")]
845 ErrAlertFatalOrClose,
846 #[error(
847 "Fragment buffer overflow. New size {new_size} is greater than specified max {max_size}"
848 )]
849 ErrFragmentBufferOverflow { new_size: usize, max_size: usize },
850 #[error("Client transport is not set yet")]
851 ErrClientTransportNotSet,
852
853 #[error("{0}")]
854 Sec1(#[source] sec1::Error),
855 #[error("{0}")]
856 P256(#[source] P256Error),
857 #[error("{0}")]
858 RcGen(#[from] rcgen::Error),
859
860 #[error("invalid PEM: {0}")]
862 InvalidPEM(String),
863
864 #[error("endpoint stopping")]
868 EndpointStopping,
869 #[error("too many connections")]
873 TooManyConnections,
874 #[error("invalid DNS name: {0}")]
876 InvalidDnsName(String),
877 #[error("invalid remote address: {0}")]
881 InvalidRemoteAddress(SocketAddr),
882 #[error("no client config")]
884 NoClientConfig,
885 #[error("no server config")]
887 NoServerConfig,
888
889 #[error("raw is too small for a SCTP chunk")]
891 ErrChunkHeaderTooSmall,
892 #[error("not enough data left in SCTP packet to satisfy requested length")]
893 ErrChunkHeaderNotEnoughSpace,
894 #[error("chunk PADDING is non-zero at offset")]
895 ErrChunkHeaderPaddingNonZero,
896 #[error("chunk has invalid length")]
897 ErrChunkHeaderInvalidLength,
898
899 #[error("ChunkType is not of type ABORT")]
900 ErrChunkTypeNotAbort,
901 #[error("failed build Abort Chunk")]
902 ErrBuildAbortChunkFailed,
903 #[error("ChunkType is not of type COOKIEACK")]
904 ErrChunkTypeNotCookieAck,
905 #[error("ChunkType is not of type COOKIEECHO")]
906 ErrChunkTypeNotCookieEcho,
907 #[error("ChunkType is not of type ctError")]
908 ErrChunkTypeNotCt,
909 #[error("failed build Error Chunk")]
910 ErrBuildErrorChunkFailed,
911 #[error("failed to marshal stream")]
912 ErrMarshalStreamFailed,
913 #[error("chunk too short")]
914 ErrChunkTooShort,
915 #[error("ChunkType is not of type ForwardTsn")]
916 ErrChunkTypeNotForwardTsn,
917 #[error("ChunkType is not of type HEARTBEAT")]
918 ErrChunkTypeNotHeartbeat,
919 #[error("ChunkType is not of type HEARTBEATACK")]
920 ErrChunkTypeNotHeartbeatAck,
921 #[error("heartbeat is not long enough to contain Heartbeat Info")]
922 ErrHeartbeatNotLongEnoughInfo,
923 #[error("failed to parse param type")]
924 ErrParseParamTypeFailed,
925 #[error("heartbeat should only have HEARTBEAT param")]
926 ErrHeartbeatParam,
927 #[error("failed unmarshalling param in Heartbeat Chunk")]
928 ErrHeartbeatChunkUnmarshal,
929 #[error("unimplemented")]
930 ErrUnimplemented,
931 #[error("heartbeat Ack must have one param")]
932 ErrHeartbeatAckParams,
933 #[error("heartbeat Ack must have one param, and it should be a HeartbeatInfo")]
934 ErrHeartbeatAckNotHeartbeatInfo,
935 #[error("unable to marshal parameter for Heartbeat Ack")]
936 ErrHeartbeatAckMarshalParam,
937
938 #[error("raw is too small for error cause")]
939 ErrErrorCauseTooSmall,
940
941 #[error("unhandled ParamType")]
942 ErrParamTypeUnhandled,
943
944 #[error("unexpected ParamType")]
945 ErrParamTypeUnexpected,
946
947 #[error("param header too short")]
948 ErrParamHeaderTooShort,
949 #[error("param self reported length is shorter than header length")]
950 ErrParamHeaderSelfReportedLengthShorter,
951 #[error("param self reported length is longer than header length")]
952 ErrParamHeaderSelfReportedLengthLonger,
953 #[error("failed to parse param type")]
954 ErrParamHeaderParseFailed,
955
956 #[error("packet to short")]
957 ErrParamPacketTooShort,
958 #[error("outgoing SSN reset request parameter too short")]
959 ErrSsnResetRequestParamTooShort,
960 #[error("reconfig response parameter too short")]
961 ErrReconfigRespParamTooShort,
962 #[error("invalid algorithm type")]
963 ErrInvalidAlgorithmType,
964
965 #[error("failed to parse param type")]
966 ErrInitChunkParseParamTypeFailed,
967 #[error("failed unmarshalling param in Init Chunk")]
968 ErrInitChunkUnmarshalParam,
969 #[error("unable to marshal parameter for INIT/INITACK")]
970 ErrInitAckMarshalParam,
971
972 #[error("ChunkType is not of type INIT")]
973 ErrChunkTypeNotTypeInit,
974 #[error("chunk Value isn't long enough for mandatory parameters exp")]
975 ErrChunkValueNotLongEnough,
976 #[error("ChunkType of type INIT flags must be all 0")]
977 ErrChunkTypeInitFlagZero,
978 #[error("failed to unmarshal INIT body")]
979 ErrChunkTypeInitUnmarshalFailed,
980 #[error("failed marshaling INIT common data")]
981 ErrChunkTypeInitMarshalFailed,
982 #[error("ChunkType of type INIT ACK InitiateTag must not be 0")]
983 ErrChunkTypeInitInitiateTagZero,
984 #[error("INIT ACK inbound stream request must be > 0")]
985 ErrInitInboundStreamRequestZero,
986 #[error("INIT ACK outbound stream request must be > 0")]
987 ErrInitOutboundStreamRequestZero,
988 #[error("INIT ACK Advertised Receiver Window Credit (a_rwnd) must be >= 1500")]
989 ErrInitAdvertisedReceiver1500,
990
991 #[error("packet is smaller than the header size")]
992 ErrChunkPayloadSmall,
993 #[error("ChunkType is not of type PayloadData")]
994 ErrChunkTypeNotPayloadData,
995 #[error("ChunkType is not of type Reconfig")]
996 ErrChunkTypeNotReconfig,
997 #[error("ChunkReconfig has invalid ParamA")]
998 ErrChunkReconfigInvalidParamA,
999
1000 #[error("failed to parse param type")]
1001 ErrChunkParseParamTypeFailed,
1002 #[error("unable to marshal parameter A for reconfig")]
1003 ErrChunkMarshalParamAReconfigFailed,
1004 #[error("unable to marshal parameter B for reconfig")]
1005 ErrChunkMarshalParamBReconfigFailed,
1006
1007 #[error("ChunkType is not of type SACK")]
1008 ErrChunkTypeNotSack,
1009 #[error("SACK Chunk size is not large enough to contain header")]
1010 ErrSackSizeNotLargeEnoughInfo,
1011
1012 #[error("invalid chunk size")]
1013 ErrInvalidChunkSize,
1014 #[error("ChunkType is not of type SHUTDOWN")]
1015 ErrChunkTypeNotShutdown,
1016
1017 #[error("ChunkType is not of type SHUTDOWN-ACK")]
1018 ErrChunkTypeNotShutdownAck,
1019 #[error("ChunkType is not of type SHUTDOWN-COMPLETE")]
1020 ErrChunkTypeNotShutdownComplete,
1021
1022 #[error("raw is smaller than the minimum length for a SCTP packet")]
1023 ErrPacketRawTooSmall,
1024 #[error("unable to parse SCTP chunk, not enough data for complete header")]
1025 ErrParseSctpChunkNotEnoughData,
1026 #[error("failed to unmarshal, contains unknown chunk type")]
1027 ErrUnmarshalUnknownChunkType,
1028 #[error("checksum mismatch theirs")]
1029 ErrChecksumMismatch,
1030
1031 #[error("unexpected chunk popped (unordered)")]
1032 ErrUnexpectedChuckPoppedUnordered,
1033 #[error("unexpected chunk popped (ordered)")]
1034 ErrUnexpectedChuckPoppedOrdered,
1035 #[error("unexpected q state (should've been selected)")]
1036 ErrUnexpectedQState,
1037 #[error("try again")]
1038 ErrTryAgain,
1039
1040 #[error("abort chunk, with following errors: {0}")]
1041 ErrAbortChunk(String),
1042 #[error("shutdown called in non-Established state")]
1043 ErrShutdownNonEstablished,
1044 #[error("association closed before connecting")]
1045 ErrAssociationClosedBeforeConn,
1046 #[error("association init failed")]
1047 ErrAssociationInitFailed,
1048 #[error("association handshake closed")]
1049 ErrAssociationHandshakeClosed,
1050 #[error("silently discard")]
1051 ErrSilentlyDiscard,
1052 #[error("the init not stored to send")]
1053 ErrInitNotStoredToSend,
1054 #[error("cookieEcho not stored to send")]
1055 ErrCookieEchoNotStoredToSend,
1056 #[error("sctp packet must not have a source port of 0")]
1057 ErrSctpPacketSourcePortZero,
1058 #[error("sctp packet must not have a destination port of 0")]
1059 ErrSctpPacketDestinationPortZero,
1060 #[error("init chunk must not be bundled with any other chunk")]
1061 ErrInitChunkBundled,
1062 #[error("init chunk expects a verification tag of 0 on the packet when out-of-the-blue")]
1063 ErrInitChunkVerifyTagNotZero,
1064 #[error("todo: handle Init when in state")]
1065 ErrHandleInitState,
1066 #[error("no cookie in InitAck")]
1067 ErrInitAckNoCookie,
1068 #[error("there already exists a stream with identifier")]
1069 ErrStreamAlreadyExist,
1070 #[error("Failed to create a stream with identifier")]
1071 ErrStreamCreateFailed,
1072 #[error("unable to be popped from inflight queue TSN")]
1073 ErrInflightQueueTsnPop,
1074 #[error("requested non-existent TSN")]
1075 ErrTsnRequestNotExist,
1076 #[error("sending reset packet in non-Established state")]
1077 ErrResetPacketInStateNotExist,
1078 #[error("unexpected parameter type")]
1079 ErrParameterType,
1080 #[error("sending payload data in non-Established state")]
1081 ErrPayloadDataStateNotExist,
1082 #[error("unhandled chunk type")]
1083 ErrChunkTypeUnhandled,
1084 #[error("handshake failed (INIT ACK)")]
1085 ErrHandshakeInitAck,
1086 #[error("handshake failed (COOKIE ECHO)")]
1087 ErrHandshakeCookieEcho,
1088
1089 #[error("outbound packet larger than maximum message size")]
1090 ErrOutboundPacketTooLarge,
1091 #[error("Stream closed")]
1092 ErrStreamClosed,
1093 #[error("Stream not existed")]
1094 ErrStreamNotExisted,
1095 #[error("Association not existed")]
1096 ErrAssociationNotExisted,
1097 #[error("Io EOF")]
1098 ErrEof,
1099 #[error("Invalid SystemTime")]
1100 ErrInvalidSystemTime,
1101 #[error("Net Conn read error")]
1102 ErrNetConnRead,
1103 #[error("Max Data Channel ID")]
1104 ErrMaxDataChannelID,
1105
1106 #[error(
1108 "DataChannel message is not long enough to determine type: (expected: {expected}, actual: {actual})"
1109 )]
1110 UnexpectedEndOfBuffer { expected: usize, actual: usize },
1111 #[error("Unknown MessageType {0}")]
1112 InvalidMessageType(u8),
1113 #[error("Unknown ChannelType {0}")]
1114 InvalidChannelType(u8),
1115 #[error("Unknown PayloadProtocolIdentifier {0}")]
1116 InvalidPayloadProtocolIdentifier(u8),
1117 #[error("Unknow Protocol")]
1118 UnknownProtocol,
1119
1120 #[error("aes gcm: {0}")]
1124 AesGcm(#[from] aes_gcm::Error),
1125 #[error("parse ip: {0}")]
1128 ParseIp(#[from] net::AddrParseError),
1129 #[error("parse int: {0}")]
1130 ParseInt(#[from] ParseIntError),
1131 #[error("{0}")]
1132 Io(#[source] IoError),
1133 #[error("url parse: {0}")]
1134 Url(#[from] url::ParseError),
1135 #[error("utf8: {0}")]
1136 Utf8(#[from] FromUtf8Error),
1137 #[error("{0}")]
1138 Std(#[source] StdError),
1139 #[error("{0}")]
1140 Aes(#[from] aes::cipher::InvalidLength),
1141
1142 #[error("Other RTCP Err: {0}")]
1144 OtherRtcpErr(String),
1145 #[error("Other RTP Err: {0}")]
1146 OtherRtpErr(String),
1147 #[error("Other SRTP Err: {0}")]
1148 OtherSrtpErr(String),
1149 #[error("Other STUN Err: {0}")]
1150 OtherStunErr(String),
1151 #[error("Other TURN Err: {0}")]
1152 OtherTurnErr(String),
1153 #[error("Other ICE Err: {0}")]
1154 OtherIceErr(String),
1155 #[error("Other DTLS Err: {0}")]
1156 OtherDtlsErr(String),
1157 #[error("Other SCTP Err: {0}")]
1158 OtherSctpErr(String),
1159 #[error("Other DataChannel Err: {0}")]
1160 OtherDataChannelErr(String),
1161 #[error("Other Interceptor Err: {0}")]
1162 OtherInterceptorErr(String),
1163 #[error("Other Media Err: {0}")]
1164 OtherMediaErr(String),
1165 #[error("Other mDNS Err: {0}")]
1166 OtherMdnsErr(String),
1167 #[error("Other SDP Err: {0}")]
1168 OtherSdpErr(String),
1169 #[error("Other PeerConnection Err: {0}")]
1170 OtherPeerConnectionErr(String),
1171 #[error("{0}")]
1172 Other(String),
1173}
1174
1175impl Error {
1176 pub fn from_std<T>(error: T) -> Self
1177 where
1178 T: std::error::Error + Send + Sync + 'static,
1179 {
1180 Error::Std(StdError(Box::new(error)))
1181 }
1182
1183 pub fn downcast_ref<T: std::error::Error + 'static>(&self) -> Option<&T> {
1184 if let Error::Std(s) = self {
1185 return s.0.downcast_ref();
1186 }
1187
1188 None
1189 }
1190}
1191
1192#[derive(Debug, Error)]
1193#[error("io error: {0}")]
1194pub struct IoError(#[from] pub io::Error);
1195
1196impl PartialEq for IoError {
1198 fn eq(&self, other: &Self) -> bool {
1199 self.0.kind() == other.0.kind()
1200 }
1201}
1202
1203impl From<io::Error> for Error {
1204 fn from(e: io::Error) -> Self {
1205 Error::Io(IoError(e))
1206 }
1207}
1208
1209#[derive(Debug, Error)]
1218#[error("{0}")]
1219pub struct StdError(pub Box<dyn std::error::Error + Send + Sync>);
1220
1221impl PartialEq for StdError {
1222 fn eq(&self, _: &Self) -> bool {
1223 false
1224 }
1225}
1226
1227impl<T> From<std::sync::PoisonError<T>> for Error {
1228 fn from(e: std::sync::PoisonError<T>) -> Self {
1229 Error::PoisonError(e.to_string())
1230 }
1231}
1232
1233impl From<sec1::Error> for Error {
1234 fn from(e: sec1::Error) -> Self {
1235 Error::Sec1(e)
1236 }
1237}
1238
1239#[derive(Debug, Error)]
1240#[error("{0}")]
1241pub struct P256Error(#[source] p256::elliptic_curve::Error);
1242
1243impl PartialEq for P256Error {
1244 fn eq(&self, _: &Self) -> bool {
1245 false
1246 }
1247}
1248
1249impl From<p256::elliptic_curve::Error> for Error {
1250 fn from(e: p256::elliptic_curve::Error) -> Self {
1251 Error::P256(P256Error(e))
1252 }
1253}
1254
1255impl From<SystemTimeError> for Error {
1256 fn from(e: SystemTimeError) -> Self {
1257 Error::Other(e.to_string())
1258 }
1259}