Skip to main content

irontide_wire/mse/
mod.rs

1//! Message Stream Encryption / Protocol Encryption (MSE/PE).
2//!
3//! Obfuscates `BitTorrent` traffic using Diffie-Hellman key exchange and RC4 stream cipher.
4
5pub(crate) mod cipher;
6pub(crate) mod crypto;
7pub(crate) mod dh;
8pub mod handshake;
9pub mod stream;
10
11use serde::{Deserialize, Serialize};
12
13pub use crypto::{CRYPTO_PLAINTEXT, CRYPTO_RC4};
14pub use handshake::NegotiationResult;
15pub use stream::MseStream;
16
17/// Encryption mode for peer connections.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
19pub enum EncryptionMode {
20    /// No encryption. Plain `BitTorrent` handshake.
21    #[default]
22    Disabled,
23    /// Offer both plaintext and RC4, let peer choose. Fallback to plain on MSE failure.
24    Enabled,
25    /// Offer plaintext-only first; if the peer rejects, retry offering both
26    /// plaintext and RC4. This avoids unnecessary RC4 overhead when the peer
27    /// accepts plaintext, while still connecting to RC4-only peers via retry.
28    PreferPlaintext,
29    /// Encrypted only. Reject unencrypted peers.
30    Forced,
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn encryption_mode_default_is_disabled() {
39        assert_eq!(EncryptionMode::default(), EncryptionMode::Disabled);
40    }
41}