Skip to content

Commit f17d3bd

Browse files
committed
Separate ohttp key_config module from lib
OHTTP KeyConfig management is about to get more complex.
1 parent b2aba5e commit f17d3bd

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Manage the OHTTP key configuration
2+
3+
use anyhow::Result;
4+
use tracing::info;
5+
6+
pub fn init_ohttp() -> Result<ohttp::Server> {
7+
use ohttp::hpke::{Aead, Kdf, Kem};
8+
use ohttp::{KeyId, SymmetricSuite};
9+
10+
const KEY_ID: KeyId = 1;
11+
const KEM: Kem = Kem::K256Sha256;
12+
const SYMMETRIC: &[SymmetricSuite] =
13+
&[SymmetricSuite::new(Kdf::HkdfSha256, Aead::ChaCha20Poly1305)];
14+
15+
// create or read from file
16+
let server_config = ohttp::KeyConfig::new(KEY_ID, KEM, Vec::from(SYMMETRIC))?;
17+
info!("Initialized a new OHTTP Key Configuration. GET /ohttp-keys to fetch it.");
18+
Ok(ohttp::Server::new(server_config)?)
19+
}

payjoin-directory/src/lib.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ use hyper_util::rt::TokioIo;
1515
use payjoin::directory::{ShortId, ShortIdError, ENCAPSULATED_MESSAGE_BYTES};
1616
use tokio::net::TcpListener;
1717
use tokio::sync::Mutex;
18-
use tracing::{debug, error, info, trace};
18+
use tracing::{debug, error, trace};
1919

2020
use crate::db::DbPool;
21+
mod key_config;
22+
use crate::key_config::init_ohttp;
2123

2224
pub const DEFAULT_DIR_PORT: u16 = 8080;
2325
pub const DEFAULT_DB_HOST: &str = "localhost:6379";
@@ -158,21 +160,6 @@ fn init_tls_acceptor(cert_key: (Vec<u8>, Vec<u8>)) -> Result<tokio_rustls::TlsAc
158160
Ok(TlsAcceptor::from(Arc::new(server_config)))
159161
}
160162

161-
fn init_ohttp() -> Result<ohttp::Server> {
162-
use ohttp::hpke::{Aead, Kdf, Kem};
163-
use ohttp::{KeyId, SymmetricSuite};
164-
165-
const KEY_ID: KeyId = 1;
166-
const KEM: Kem = Kem::K256Sha256;
167-
const SYMMETRIC: &[SymmetricSuite] =
168-
&[SymmetricSuite::new(Kdf::HkdfSha256, Aead::ChaCha20Poly1305)];
169-
170-
// create or read from file
171-
let server_config = ohttp::KeyConfig::new(KEY_ID, KEM, Vec::from(SYMMETRIC))?;
172-
info!("Initialized a new OHTTP Key Configuration. GET /ohttp-keys to fetch it.");
173-
Ok(ohttp::Server::new(server_config)?)
174-
}
175-
176163
async fn serve_payjoin_directory(
177164
req: Request<Incoming>,
178165
pool: DbPool,

0 commit comments

Comments
 (0)