Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions compat/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"

[dependencies]
arbitrary = { version = "1", optional = true, features = ["derive"] }
libtelnet-rs = "2.0.0"
libmudtelnet = { path = "..", features = ["arbitrary"] }
bencher = "0.1.5"
rand = "0.8.5"
Expand Down
48 changes: 2 additions & 46 deletions compat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use libmudtelnet::compatibility::CompatibilityTable;
use libmudtelnet::events::{TelnetEvents, TelnetIAC, TelnetNegotiation, TelnetSubnegotiation};
use libmudtelnet::Parser;

use libtelnet_rs::compatibility::CompatibilityTable as OgCompatibilityTable;
use libtelnet_rs::events::TelnetEvents as OgTelnetEvents;
use libtelnet_rs::Parser as OgParser;

#[derive(Debug, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct TelnetApplication {
Expand All @@ -15,52 +10,13 @@ pub struct TelnetApplication {

pub fn test_app(app: &TelnetApplication) {
let mut parser = Parser::with_support(CompatibilityTable::from_options(&app.options));
let mut og_parser = OgParser::with_support(OgCompatibilityTable::from_options(&app.options));

for data in &app.received_data {
let our_events = parser.receive(&data);
let og_events = events(og_parser.receive(&data));
assert_eq!(our_events, og_events);
}

for i in 0..255 {
assert_eq!(
parser.options.get_option(i).into_u8(),
og_parser.options.get_option(i).into_u8()
);
}
}

pub fn events(events: Vec<OgTelnetEvents>) -> Vec<TelnetEvents> {
events.into_iter().map(event).collect()
}

pub fn event(event: OgTelnetEvents) -> TelnetEvents {
match event {
OgTelnetEvents::IAC(iac) => TelnetEvents::IAC(TelnetIAC::new(iac.command)),
OgTelnetEvents::Negotiation(neg) => {
TelnetEvents::Negotiation(TelnetNegotiation::new(neg.command, neg.option))
}
OgTelnetEvents::Subnegotiation(sub) => {
TelnetEvents::Subnegotiation(TelnetSubnegotiation::new(sub.option, sub.buffer))
}
OgTelnetEvents::DataReceive(data) => TelnetEvents::DataReceive(data),
OgTelnetEvents::DataSend(data) => TelnetEvents::DataSend(data),
OgTelnetEvents::DecompressImmediate(data) => TelnetEvents::DecompressImmediate(data),
parser.receive(data);
}
}

pub fn test_escape(data: Vec<u8>) {
// For any input if we escape it, and then unescape it, we should get back the original data.
let escaped = Parser::escape_iac(data.clone());
let unescaped = Parser::unescape_iac(escaped.clone());
let unescaped = Parser::unescape_iac(escaped);
assert_eq!(data, unescaped);

// The same should be true for the original implementation.
let og_escaped = OgParser::escape_iac(data.clone());
let og_unescaped = OgParser::unescape_iac(og_escaped.clone());
assert_eq!(data, og_unescaped);

// And we expect the new and old implementation produce the same escaped output.
assert_eq!(escaped, og_escaped);
}
2 changes: 0 additions & 2 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ path = "parser/escape.rs"
test = false
doc = false

[patch.crates-io]
libtelnet-rs = { git = "https://github.com/cpu/libtelnet-rs", branch = "cpu-libmudtelnet-compat" }