Skip to content

Commit d290dfb

Browse files
committed
Update code to use borsh v1 APIs
1 parent 89e3535 commit d290dfb

File tree

5 files changed

+134
-53
lines changed

5 files changed

+134
-53
lines changed

src/Cargo.lock

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

src/integration/src/bin/pivot_remote_tls.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
sync::Arc,
55
};
66

7-
use borsh::{BorshDeserialize, BorshSerialize};
7+
use borsh::BorshDeserialize;
88
use integration::PivotRemoteTlsMsg;
99
use qos_core::{
1010
io::{SocketAddress, TimeVal},
@@ -86,10 +86,9 @@ impl RequestProcessor for Processor {
8686

8787
let fetched_content =
8888
std::str::from_utf8(&response_bytes).unwrap();
89-
PivotRemoteTlsMsg::RemoteTlsResponse(format!(
89+
borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsResponse(format!(
9090
"Content fetched successfully: {fetched_content}"
91-
))
92-
.try_to_vec()
91+
)))
9392
.expect("RemoteTlsResponse is valid borsh")
9493
}
9594
PivotRemoteTlsMsg::RemoteTlsResponse(_) => {
Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
#[cfg(test)]
22
mod tests {
3-
use borsh::{BorshSerialize, BorshDeserialize};
3+
use borsh::{BorshDeserialize, BorshSerialize};
44

5-
#[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)]
6-
struct TestSerializable {
7-
a: u32,
8-
b: String,
9-
c: Vec<u8>,
10-
}
5+
#[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)]
6+
struct TestSerializable {
7+
a: u32,
8+
b: String,
9+
c: Vec<u8>,
10+
}
1111

12-
#[test]
13-
fn test_serializable_to_vec() {
14-
let inst = TestSerializable {
15-
a: 42,
16-
b: "Hello, world!".to_string(),
17-
c: vec![1, 2, 3, 4, 5],
18-
};
12+
#[test]
13+
fn test_serializable_to_vec() {
14+
let inst = TestSerializable {
15+
a: 42,
16+
b: "Hello, world!".to_string(),
17+
c: vec![1, 2, 3, 4, 5],
18+
};
1919

20-
// Expected serialized output
21-
let expected_serialized: Vec<u8> = vec![
22-
42, 0, 0, 0, // a: u32 (little-endian)
23-
13, 0, 0, 0, // Length of the string b (13)
24-
72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, // "Hello, world!" as bytes
25-
5, 0, 0, 0, // Length of the vector c (5)
26-
1, 2, 3, 4, 5 // c: Vec<u8>
27-
];
20+
// Expected serialized output
21+
let expected_serialized: Vec<u8> = vec![
22+
42, 0, 0, 0, // a: u32 (little-endian)
23+
13, 0, 0, 0, // Length of the string b (13)
24+
72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100,
25+
33, // "Hello, world!" as bytes
26+
5, 0, 0, 0, // Length of the vector c (5)
27+
1, 2, 3, 4, 5, // c: Vec<u8>
28+
];
2829

29-
// Serialize the instance
30-
let serialized = borsh::to_vec(&inst).expect("Serialization failed");
30+
// Serialize the instance
31+
let serialized = borsh::to_vec(&inst).expect("Serialization failed");
3132

32-
// Assert that the serialized output matches the expected value
33-
assert_eq!(serialized, expected_serialized, "Serialized bytes differ from the expected value");
33+
// Assert that the serialized output matches the expected value
34+
assert_eq!(
35+
serialized, expected_serialized,
36+
"Serialized bytes differ from the expected value"
37+
);
3438

35-
// Deserialize the serialized data back to a new instance
36-
let deserialized_inst: TestSerializable = borsh::BorshDeserialize::try_from_slice(&serialized)
37-
.expect("Deserialization failed");
39+
// Deserialize the serialized data back to a new instance
40+
let deserialized_inst: TestSerializable =
41+
borsh::BorshDeserialize::try_from_slice(&serialized)
42+
.expect("Deserialization failed");
3843

39-
// Assert that the deserialized instance matches the original instance
40-
assert_eq!(deserialized_inst, inst, "Deserialized instance differs from the original");
41-
}
44+
// Assert that the deserialized instance matches the original instance
45+
assert_eq!(
46+
deserialized_inst, inst,
47+
"Deserialized instance differs from the original"
48+
);
49+
}
4250
}

src/integration/tests/remote_tls.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{process::Command, str};
22

3-
use borsh::BorshSerialize;
43
use integration::{PivotRemoteTlsMsg, PIVOT_REMOTE_TLS_PATH, QOS_NET_PATH};
54
use qos_core::{
65
client::Client,
@@ -34,11 +33,10 @@ fn fetch_remote_tls_content() {
3433
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS),
3534
);
3635

37-
let app_request = PivotRemoteTlsMsg::RemoteTlsRequest {
36+
let app_request = borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsRequest {
3837
host: "api.turnkey.com".to_string(),
3938
path: "/health".to_string(),
40-
}
41-
.try_to_vec()
39+
})
4240
.unwrap();
4341

4442
let response = enclave_client.send(&app_request).unwrap();
@@ -48,11 +46,10 @@ fn fetch_remote_tls_content() {
4846
assert!(response_text.contains("HTTP/1.1 200 OK"));
4947
assert!(response_text.contains("currentTime"));
5048

51-
let app_request = PivotRemoteTlsMsg::RemoteTlsRequest {
49+
let app_request = borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsRequest {
5250
host: "www.googleapis.com".to_string(),
5351
path: "/oauth2/v3/certs".to_string(),
54-
}
55-
.try_to_vec()
52+
})
5653
.unwrap();
5754

5855
let response = enclave_client.send(&app_request).unwrap();

src/qos_core/src/io/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ mod test {
403403

404404
// Send "PONG" if "PING" was sent
405405
if from_utf8(&buf).unwrap() == "PING" {
406-
stream.write(b"PONG").unwrap();
406+
let _ = stream.write(b"PONG").unwrap();
407407
}
408408

409409
// Then shutdown the server

0 commit comments

Comments
 (0)