Compare commits
2 commits
6f290c90e9
...
a563e46162
Author | SHA1 | Date | |
---|---|---|---|
a563e46162 | |||
aa4432bf37 |
3 changed files with 57 additions and 11 deletions
|
@ -43,7 +43,7 @@ type Endpoint<'a> = (reqwest::Method, &'a str);
|
|||
/// we could completely change it without requiring an upgrade to v1
|
||||
/// clients.)
|
||||
/// ```
|
||||
pub const ADD_CHAIN_ENDPOINT: Endpoint = (reqwest::Method::POST, "/ct/v1/add-chain");
|
||||
pub const ADD_CHAIN: Endpoint = (reqwest::Method::POST, "/ct/v1/add-chain");
|
||||
|
||||
/// Reference: https://datatracker.ietf.org/doc/html/rfc6962#section-4.2
|
||||
/// ```txt
|
||||
|
@ -59,4 +59,22 @@ pub const ADD_CHAIN_ENDPOINT: Endpoint = (reqwest::Method::POST, "/ct/v1/add-cha
|
|||
///
|
||||
/// Outputs are the same as in Section 4.1.
|
||||
/// ```
|
||||
pub const ADD_PRE_CHAIN_ENDPOINT: Endpoint = (reqwest::Method::POST, "/ct/v1/add-pre-chain");
|
||||
pub const ADD_PRE_CHAIN: Endpoint = (reqwest::Method::POST, "/ct/v1/add-pre-chain");
|
||||
|
||||
/// Reference: https://datatracker.ietf.org/doc/html/rfc6962#section-4.3
|
||||
/// ```txt
|
||||
/// GET https://<log server>/ct/v1/get-sth
|
||||
///
|
||||
/// No inputs.
|
||||
///
|
||||
/// Outputs:
|
||||
///
|
||||
/// tree_size: The size of the tree, in entries, in decimal.
|
||||
///
|
||||
/// timestamp: The timestamp, in decimal.
|
||||
///
|
||||
/// sha256_root_hash: The Merkle Tree Hash of the tree, in base64.
|
||||
///
|
||||
/// tree_head_signature: A TreeHeadSignature for the above data.
|
||||
/// ```
|
||||
pub const GET_STH: Endpoint = (reqwest::Method::GET, "/ct/v1/get-sth");
|
|
@ -1,5 +1,5 @@
|
|||
use reqwest::Url;
|
||||
use responses::{AddChainRequest, AddChainResponse};
|
||||
use responses::{AddChainRequest, AddChainResponse, GetSthResponse};
|
||||
|
||||
pub mod endpoints;
|
||||
pub mod responses;
|
||||
|
@ -34,8 +34,8 @@ impl CtApiClient {
|
|||
) -> reqwest::Result<AddChainResponse> {
|
||||
self.inner_client
|
||||
.request(
|
||||
endpoints::ADD_CHAIN_ENDPOINT.0,
|
||||
self.log_url.to_string() + endpoints::ADD_CHAIN_ENDPOINT.1
|
||||
endpoints::ADD_CHAIN.0,
|
||||
self.log_url.to_string() + endpoints::ADD_CHAIN.1
|
||||
)
|
||||
.json(&AddChainRequest { chain })
|
||||
.send()
|
||||
|
@ -67,8 +67,8 @@ impl CtApiClient {
|
|||
) -> reqwest::Result<AddChainResponse> {
|
||||
self.inner_client
|
||||
.request(
|
||||
endpoints::ADD_PRE_CHAIN_ENDPOINT.0,
|
||||
self.log_url.to_string() + endpoints::ADD_PRE_CHAIN_ENDPOINT.1
|
||||
endpoints::ADD_PRE_CHAIN.0,
|
||||
self.log_url.to_string() + endpoints::ADD_PRE_CHAIN.1
|
||||
)
|
||||
.json(&AddChainRequest { chain })
|
||||
.send()
|
||||
|
@ -77,4 +77,19 @@ impl CtApiClient {
|
|||
.json()
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_signed_tree_head(
|
||||
&self
|
||||
) -> reqwest::Result<GetSthResponse> {
|
||||
self.inner_client
|
||||
.request(
|
||||
endpoints::GET_STH.0,
|
||||
self.log_url.to_string() + endpoints::GET_STH.1
|
||||
)
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.json()
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,17 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
/// A request payload for adding a chain to a CT log
|
||||
///
|
||||
/// See: [`super::endpoints::ADD_CHAIN_ENDPOINT`] or [`super::endpoints::ADD_PRE_CHAIN_ENDPOINT`]
|
||||
/// See: [`super::endpoints::ADD_CHAIN`] or
|
||||
/// [`super::endpoints::ADD_PRE_CHAIN`]
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct AddChainRequest {
|
||||
pub chain: Vec<String>
|
||||
pub chain: Vec<String>
|
||||
}
|
||||
|
||||
/// A response given when adding a chain to a CT log
|
||||
///
|
||||
/// See: [`super::endpoints::ADD_CHAIN_ENDPOINT`] or [`super::endpoints::ADD_PRE_CHAIN_ENDPOINT`]
|
||||
/// See: [`super::endpoints::ADD_CHAIN`] or
|
||||
/// [`super::endpoints::ADD_PRE_CHAIN`]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct AddChainResponse {
|
||||
pub sct_version: u8,
|
||||
|
@ -19,3 +21,14 @@ pub struct AddChainResponse {
|
|||
pub extensions: String,
|
||||
pub signature: String
|
||||
}
|
||||
|
||||
/// A response given when fetching the Signed Tree Head of a CT log
|
||||
///
|
||||
/// See: [`super::endpoints::GET_STH`]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct GetSthResponse {
|
||||
pub tree_size: u64,
|
||||
pub timestamp: u64,
|
||||
pub sha256_root_hash: String,
|
||||
pub tree_head_signature: String
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue