Skip to content

Commit d924bd6

Browse files
authored
misc(notary): add common crate for server and client (#871)
* Add notary-common crate. * Add cargo lock changes. * Add copy. --------- Co-authored-by: yuroitaki <>
1 parent b3558be commit d924bd6

File tree

14 files changed

+68
-48
lines changed

14 files changed

+68
-48
lines changed

Cargo.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"crates/examples",
1616
"crates/formats",
1717
"crates/notary/client",
18+
"crates/notary/common",
1819
"crates/notary/server",
1920
"crates/notary/tests-integration",
2021
"crates/prover",
@@ -45,6 +46,7 @@ opt-level = 1
4546

4647
[workspace.dependencies]
4748
notary-client = { path = "crates/notary/client" }
49+
notary-common = { path = "crates/notary/common" }
4850
notary-server = { path = "crates/notary/server" }
4951
tls-server-fixture = { path = "crates/tls/server-fixture" }
5052
tlsn-cipher = { path = "crates/components/cipher" }

crates/notary/client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
workspace = true
88

99
[dependencies]
10-
notary-server = { workspace = true }
10+
notary-common = { workspace = true }
1111

1212
derive_builder = { workspace = true }
1313
futures = { workspace = true }

crates/notary/client/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use hyper::{
1010
Request, Response, StatusCode,
1111
};
1212
use hyper_util::rt::TokioIo;
13-
use notary_server::{
13+
use notary_common::{
1414
ClientType, NotarizationSessionRequest, NotarizationSessionResponse, X_API_KEY_HEADER,
1515
};
1616
use std::{

crates/notary/common/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "notary-common"
3+
version = "0.1.0-alpha.11-pre"
4+
description = "Common code shared between notary-server and notary-client"
5+
edition = "2021"
6+
7+
[lints]
8+
workspace = true
9+
10+
[dependencies]
11+
serde = { workspace = true, features = ["derive"] }

crates/notary/common/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
/// Custom HTTP header used for specifying a whitelisted API key.
4+
pub const X_API_KEY_HEADER: &str = "X-API-Key";
5+
6+
/// Types of client that the prover is using.
7+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
8+
pub enum ClientType {
9+
/// Client that has access to the transport layer.
10+
Tcp,
11+
/// Client that cannot directly access the transport layer, e.g. browser
12+
/// extension.
13+
Websocket,
14+
}
15+
16+
/// Request object of the /session API.
17+
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
18+
#[serde(rename_all = "camelCase")]
19+
pub struct NotarizationSessionRequest {
20+
pub client_type: ClientType,
21+
/// Maximum data that can be sent by the prover.
22+
pub max_sent_data: Option<usize>,
23+
/// Maximum data that can be received by the prover.
24+
pub max_recv_data: Option<usize>,
25+
}
26+
27+
/// Response object of the /session API.
28+
#[derive(Debug, Clone, Serialize, Deserialize)]
29+
#[serde(rename_all = "camelCase")]
30+
pub struct NotarizationSessionResponse {
31+
/// Unique session id that is generated by the notary and shared to the
32+
/// prover.
33+
pub session_id: String,
34+
}

crates/notary/server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tee_quote = [
1313
]
1414

1515
[dependencies]
16+
notary-common = { workspace = true }
1617
tlsn-core = { workspace = true }
1718
tlsn-common = { workspace = true }
1819
tlsn-verifier = { workspace = true }

crates/notary/server/src/auth.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use tracing::{debug, error, info};
1212

1313
use crate::{util::parse_csv_file, NotaryServerProperties};
1414

15-
/// Custom HTTP header used for specifying a whitelisted API key
16-
pub const X_API_KEY_HEADER: &str = "X-API-Key";
17-
1815
/// Structure of each whitelisted record of the API key whitelist for
1916
/// authorization purpose
2017
#[derive(Clone, Debug, Deserialize, Serialize)]

crates/notary/server/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod tee;
1212
mod types;
1313
mod util;
1414

15-
pub use auth::X_API_KEY_HEADER;
1615
pub use cli::CliFields;
1716
pub use config::{
1817
AuthorizationProperties, LogProperties, NotarizationProperties, NotaryServerProperties,
@@ -21,5 +20,4 @@ pub use config::{
2120
pub use error::NotaryServerError;
2221
pub use server::{read_pem_file, run_server};
2322
pub use server_tracing::init_tracing;
24-
pub use types::{ClientType, NotarizationSessionRequest, NotarizationSessionResponse};
2523
pub use util::parse_config_file;

crates/notary/server/src/middleware.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use axum::http::request::Parts;
22
use axum_core::extract::{FromRef, FromRequestParts};
3+
use notary_common::X_API_KEY_HEADER;
34
use std::collections::HashMap;
45
use tracing::{error, trace};
56

6-
use crate::{
7-
auth::{AuthorizationWhitelistRecord, X_API_KEY_HEADER},
8-
types::NotaryGlobals,
9-
NotaryServerError,
10-
};
7+
use crate::{auth::AuthorizationWhitelistRecord, types::NotaryGlobals, NotaryServerError};
118

129
/// Auth middleware to prevent DOS
1310
pub struct AuthorizationMiddleware;

0 commit comments

Comments
 (0)