Skip to content

Commit

Permalink
tiebreaker
Browse files Browse the repository at this point in the history
  • Loading branch information
m4salah committed Jan 6, 2024
1 parent 2a5b398 commit 198bdd1
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ uuid = "1.6.1"
walkdir = "2.4.0"
clap = { version = "4.4.7", features = ["env", "derive"] }
tracing-subscriber = "0.3.18"
josekit = "0.8.4"

[dev-dependencies]
tower = { version = "0.4", features = ["util"] }
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod day5;
pub mod day6;
pub mod day7;
pub mod day8;
pub mod tiebreaker;

pub fn router(pool: Pool<Postgres>, geocoding_api_key: String) -> axum::Router {
axum::Router::new()
Expand All @@ -37,4 +38,5 @@ pub fn router(pool: Pool<Postgres>, geocoding_api_key: String) -> axum::Router {
.nest("/", day20::router())
.nest("/", day21::router(geocoding_api_key))
.nest("/", day22::router())
.nest("/", tiebreaker::router())
}
39 changes: 39 additions & 0 deletions src/handlers/tiebreaker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use axum::{http::StatusCode, routing::get, Router};
use josekit::jwe::{deserialize_json, RSA_OAEP_256};
use josekit::jwk::Jwk;
const KEY: &str = r#"{
"kty": "RSA",
"n": "tX4yurmjaH70PEgrVcrq6syvAzWCp3EvLmoYeq4JSQruT3r0fsEN_3iRNQ13VALZSL_k9xidlYEDqhNN6owui3uql6L8UrhmhhOeNOOYI4YOpTa9Yda_yuYFii6o_NrOpHv4LmrMzLzCX7kPW3j4GNiS7vYkwGI0n1mtVGqpYs9jic4GR3Be-kBMgNpZanJk9OA2LKf1cyh2n5LkU9lO15ZszvKfA9u_08A5s62b9_MhjEVlmENUWXGJ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LHSd11Jm4rp1yZlHZc2_3aUKsu26L1lcAjO7ianWMR58tyGdXAjUrYaPvaoZ1n8SGxQSNf___jw5rEyE",
"qi": "Q4HW9O6xx699EHeMOnyBUFxewqpEU_kIY5D36PmGeVznmXaRAPXgp3nylvkxjMALQqU4IQ6gLdqjAi-oHk_G83s2vsVc51G1GC5CKleeNpGk_AsEcOgsg_Z1x57wni5p_YmiUPuAkty6KZugCNQLS_6VM4pDs-uyDybmaFEGHWY"
}
"#;

pub fn router() -> Router {
Router::new()
.route("/tiebreaker/health", get(|| async { StatusCode::OK }))
.route("/tiebreaker/naughty_list", get(naughty_list))
}

async fn naughty_list() {
let key = Jwk::from_bytes(KEY.as_bytes()).unwrap();
let client = reqwest::Client::new();
let response = client
.get("https://www.codehunt.rs/api/naughty")
.header("Authorization", "Bearer Lb7bB6PyL1kP0hU2")
.send()
.await
.unwrap();
let encrypted = response.text().await.unwrap();
println!("{:?}", encrypted);
let decrypter = RSA_OAEP_256.decrypter_from_jwk(&key).unwrap();

let (payload, _) = deserialize_json(&encrypted, &decrypter).unwrap();

println!("{:?}", payload)
}

0 comments on commit 198bdd1

Please sign in to comment.