kochab/examples/certificates.rs
Emi Tatsuo 63c228bcfa
Replace molly brown w/ stargazer, serve examples in IP
Stargazer is available thru cargo, which makes it more accessable to new users.  Serving ip allows examples to be run in gemini_srv mode
2020-12-13 19:53:18 -05:00

34 lines
894 B
Rust

use anyhow::Result;
use log::LevelFilter;
use std::fmt::Write;
use kochab::{Request, Response, Server};
#[tokio::main]
async fn main() -> Result<()> {
env_logger::builder()
.filter_module("kochab", LevelFilter::Debug)
.init();
Server::new()
.add_route("/", handle_request)
.serve_ip("localhost:1965")
.await
}
async fn handle_request(request: Request) -> Result<Response> {
if let Some(fingerprint) = request.certificate() {
let mut message = String::from("You connected with a certificate with a fingerprint of:\n");
for byte in fingerprint {
write!(&mut message, "{:x}", byte).unwrap();
}
Ok(Response::success_plain(message))
} else {
// The user didn't provide a certificate
Ok(Response::client_certificate_required("You didn't provide a client certificate"))
}
}