Skip to content

Commit 78e7b4a

Browse files
committed
feat: migrate http request and response types from ic-response-verification to ic-http-certification
BREAKING CHANGE:
1 parent fbc7fb2 commit 78e7b4a

33 files changed

+524
-497
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ getrandom = { version = "0.2", features = ["js"] }
7676

7777

7878
ic-certification = { path = "./packages/ic-certification", default-features = false, version = "1.3.0" }
79+
ic-http-certification = { path = "./packages/ic-http-certification", version = "1.3.0" }
7980
ic-certification-testing = { path = "./packages/ic-certification-testing" }
8081
ic-representation-independent-hash = { path = "./packages/ic-representation-independent-hash", version = "1.3.0" }
8182
ic-certificate-verification = { path = "./packages/ic-certificate-verification", version = "1.3.0" }

examples/nodejs/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ try {
7070
console.log(`Error parsing cbor: ${error.message}`);
7171
break;
7272

73-
case ResponseVerificationErrorCode.MalformedUrl:
74-
console.log(`Invalid URL provided: ${error.message}`);
75-
break;
76-
7773
case ResponseVerificationErrorCode.CertificateVerificationFailed:
7874
console.log(`Certificate verification failed: ${error.message}`);
7975
break;

examples/rust/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
ic-response-verification.workspace = true
8+
ic-http-certification.workspace = true
89
candid.workspace = true
910
hex.workspace = true
1011
serde.workspace = true

examples/rust/src/main.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
1-
use candid::{CandidType, Decode, Deserialize, Principal};
2-
use ic_response_verification::types::{Request, Response};
1+
use candid::{Decode, Principal};
2+
use ic_http_certification::{HttpRequest, HttpResponse};
33
use ic_response_verification::{verify_request_response_pair, MIN_VERIFICATION_VERSION};
44

5-
#[derive(Debug, Clone, CandidType, Deserialize)]
6-
struct HttpRequest {
7-
pub url: String,
8-
pub headers: Vec<(String, String)>,
9-
#[serde(with = "serde_bytes")]
10-
pub body: Vec<u8>,
11-
}
12-
13-
#[derive(Debug, Clone, CandidType, Deserialize)]
14-
pub struct HttpResponse {
15-
pub headers: Vec<(String, String)>,
16-
#[serde(with = "serde_bytes")]
17-
pub body: Vec<u8>,
18-
}
19-
205
fn main() {
216
let request_hex = "4449444C046D7B6C02007101716D016C04EFD6E40271E1EDEB4A71A2F5ED880400C6A4A19806020103012F03474554000704486F73742372646D78362D6A616161612D61616161612D61616164712D6361692E6963302E617070066163636570748701746578742F68746D6C2C6170706C69636174696F6E2F7868746D6C2B786D6C2C6170706C69636174696F6E2F786D6C3B713D302E392C696D6167652F617669662C696D6167652F776562702C696D6167652F61706E672C2A2F2A3B713D302E382C6170706C69636174696F6E2F7369676E65642D65786368616E67653B763D62333B713D302E39097365632D63682D756128224368726F6D69756D223B763D22313037222C20224E6F743D413F4272616E64223B763D22323422107365632D63682D75612D6D6F62696C65023F30127365632D63682D75612D706C6174666F726D092257696E646F77732219757067726164652D696E7365637572652D726571756573747301310A757365722D6167656E74744D6F7A696C6C612F352E30202857696E646F7773204E542031302E303B2057696E36343B2078363429204170706C655765624B69742F3533372E333620284B48544D4C2C206C696B65204765636B6F29204368726F6D652F3130372E302E353330342E313037205361666172692F3533372E3336";
227
let request_candid = hex::decode(request_hex).expect("Could not decode request from hex");
238
let http_request =
249
Decode!(&request_candid, HttpRequest).expect("Could not decode request from candid");
25-
let request = Request {
10+
let request = HttpRequest {
2611
method: "GET".into(),
2712
url: http_request.url,
2813
headers: http_request.headers,
@@ -39,7 +24,7 @@ fn main() {
3924
let http_response =
4025
Decode!(&response_candid, HttpResponse).expect("Could not decode response from candid");
4126

42-
let response = Response {
27+
let response = HttpResponse {
4328
status_code: 200,
4429
headers: http_response.headers,
4530
body: http_response.body,

examples/service-worker/src/sw.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ self.addEventListener('activate', async () => {
7373
console.log(`Error parsing cbor: ${error.message}`);
7474
break;
7575

76-
case ResponseVerificationErrorCode.MalformedUrl:
77-
console.log(`Invalid URL provided: ${error.message}`);
78-
break;
79-
8076
case ResponseVerificationErrorCode.CertificateVerificationFailed:
8177
console.log(`Certificate verification failed: ${error.message}`);
8278
break;

examples/web/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ window.addEventListener('load', async () => {
7373
console.log(`Error parsing cbor: ${error.message}`);
7474
break;
7575

76-
case ResponseVerificationErrorCode.MalformedUrl:
77-
console.log(`Invalid URL provided: ${error.message}`);
78-
break;
79-
8076
case ResponseVerificationErrorCode.CertificateVerificationFailed:
8177
console.log(`Certificate verification failed: ${error.message}`);
8278
break;

packages/ic-http-certification/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ repository.workspace = true
1414
license.workspace = true
1515
homepage.workspace = true
1616

17+
[dependencies]
18+
candid.workspace = true
19+
serde.workspace = true
20+
http.workspace = true
21+
urlencoding.workspace = true
22+
thiserror.workspace = true
23+
1724
[dev-dependencies]
1825
rstest.workspace = true

packages/ic-http-certification/src/cel/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! The CEL modules contains functions and builders for creating CEL expression
2-
//! definitions and conveting them into their `String` representation.
1+
//! The CEL module contains functions and builders for creating CEL expression
2+
//! definitions and converting them into their `String` representation.
33
44
mod cel_builder;
55
pub use cel_builder::*;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! The error module contains types for common errors that may be thrown
2+
//! by other modules in this crate.
3+
4+
/// HTTP certification result type.
5+
pub type HttpCertificationResult<T = ()> = Result<T, HttpCertificationError>;
6+
7+
/// HTTP certification error type.
8+
#[derive(thiserror::Error, Debug)]
9+
pub enum HttpCertificationError {
10+
/// The URL was malformed and could not be parsed correctly.
11+
#[error(r#"Failed to parse url: "{0}""#)]
12+
MalformedUrl(String),
13+
14+
/// Error converting UTF-8 string.
15+
#[error(r#"Error converting UTF8 string bytes: "{0}""#)]
16+
Utf8ConversionError(#[from] std::string::FromUtf8Error),
17+
}

0 commit comments

Comments
 (0)