Skip to content

Commit

Permalink
Add function, test, module
Browse files Browse the repository at this point in the history
  • Loading branch information
ckcr4lyf committed Mar 2, 2022
1 parent 4f6c45d commit 80e8c8b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
actix-web = "4"
serde = { version = "1.0.136", features = ["derive"] }
serde = { version = "1.0.136", features = ["derive"] }
hex = "*"
25 changes: 24 additions & 1 deletion src/byte_functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
mod tests;

use hex;

pub fn do_nothing() {
println!("XD");
}
}

pub fn url_encoded_to_hex(urlenc: &str) -> String {
let mut hex_str = String::new();

for i in 0..urlenc.chars().count() {

let the_char = urlenc.chars().nth(i).expect("Shits fucked up yo");



if the_char == '%' {
hex_str.push_str(&urlenc[i+1..i+3]);
} else {
hex_str.push_str(&hex::encode(the_char.to_string()));
}
}

return hex_str;
}
4 changes: 4 additions & 0 deletions src/byte_functions/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn is_legit(){
assert_eq!("41", super::url_encoded_to_hex("A"))
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn healthz() -> impl Responder {
#[get("/announce")]
async fn announce(params: web::Query<AnnounceRequest>) -> impl Responder {
byte_functions::do_nothing();
println!("Got the following params: {:?}", params.infohash);
println!("Got the following params: {:?}", byte_functions::url_encoded_to_hex(&params.infohash));
return "GG";
}

Expand Down

0 comments on commit 80e8c8b

Please sign in to comment.