| 27 | } |
| 28 | |
| 29 | async fn make_encrypted( |
| 30 | cipher: Data<Aes256GcmSiv>, |
| 31 | Json(Req { id, data, .. }): Json<Req>, |
| 32 | ) -> impl Responder { |
| 33 | log::info!("creating encrypted sample request for ID = {id:?}"); |
| 34 | |
| 35 | // this nonce should actually be unique per message in a production environment |
| 36 | let nonce = Nonce::from_slice(b"unique nonce"); |
| 37 | let nonce_b64 = Some(BASE64_STANDARD.encode(nonce)); |
| 38 | |
| 39 | let data_enc = cipher.encrypt(nonce, data.as_bytes()).unwrap(); |
| 40 | let data_enc = BASE64_STANDARD.encode(data_enc); |
| 41 | |
| 42 | web::Json(Req { |
| 43 | id, |
| 44 | nonce: nonce_b64, |
| 45 | data: data_enc, |
| 46 | }) |
| 47 | } |
| 48 | |
| 49 | async fn reverse_data(Json(Req { id, data, .. }): Json<Req>) -> impl Responder { |
| 50 | log::info!("request {id:?} with data: {data}"); |