MCPcopy Create free account
hub / github.com/actix/examples / make_encrypted

Function make_encrypted

middleware/encrypted-payloads/src/main.rs:29–47  ·  view source on GitHub ↗
(
    cipher: Data<Aes256GcmSiv>,
    Json(Req { id, data, .. }): Json<Req>,
)

Source from the content-addressed store, hash-verified

27}
28
29async 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
49async fn reverse_data(Json(Req { id, data, .. }): Json<Req>) -> impl Responder {
50 log::info!("request {id:?} with data: {data}");

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.80

Tested by

no test coverage detected