Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peter/mock #91

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 102 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,104 @@
resolver = "2"
members = [
"crates/enclave",
"crates/enclave/derive",
"crates/enclave-server",
]

[workspace.lints]
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rust.unreachable_pub = "warn"
rust.unused_must_use = "deny"

[workspace.lints.clippy]
# These are some of clippy's nursery (i.e., experimental) lints that we like.
# By default, nursery lints are allowed. Some of the lints below have made good
# suggestions which we fixed. The others didn't have any findings, so we can
# assume they don't have that many false positives. Let's enable them to
# prevent future problems.
borrow_as_ptr = "warn"
branches_sharing_code = "warn"
clear_with_drain = "warn"
cloned_instead_of_copied = "warn"
collection_is_never_read = "warn"
dbg_macro = "warn"
derive_partial_eq_without_eq = "warn"
doc_markdown = "warn"
empty_line_after_doc_comments = "warn"
empty_line_after_outer_attr = "warn"
enum_glob_use = "warn"
equatable_if_let = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
flat_map_option = "warn"
from_iter_instead_of_collect = "warn"
if_not_else = "warn"
if_then_some_else_none = "warn"
implicit_clone = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_on_single_items = "warn"
iter_with_drain = "warn"
iter_without_into_iter = "warn"
large_stack_frames = "warn"
manual_assert = "warn"
manual_clamp = "warn"
manual_is_variant_and = "warn"
manual_string_new = "warn"
match_same_arms = "warn"
missing_const_for_fn = "warn"
mutex_integer = "warn"
naive_bytecount = "warn"
needless_bitwise_bool = "warn"
needless_continue = "warn"
needless_for_each = "warn"
needless_pass_by_ref_mut = "warn"
nonstandard_macro_braces = "warn"
option_as_ref_cloned = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
redundant_clone = "warn"
redundant_else = "warn"
single_char_pattern = "warn"
string_lit_as_bytes = "warn"
string_lit_chars_any = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_undefined_repr = "warn"
trivial_regex = "warn"
tuple_array_conversions = "warn"
type_repetition_in_bounds = "warn"
uninhabited_references = "warn"
unnecessary_self_imports = "warn"
unnecessary_struct_initialization = "warn"
unnested_or_patterns = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
use_self = "warn"
useless_let_if_seq = "warn"
while_float = "warn"
zero_sized_map_values = "warn"

# These are nursery lints which have findings. Allow them for now. Some are not
# quite mature enough for use in our codebase and some we don't really want.
# Explicitly listing should make it easier to fix in the future.
as_ptr_cast_mut = "allow"
cognitive_complexity = "allow"
debug_assert_with_mut_call = "allow"
fallible_impl_from = "allow"
future_not_send = "allow"
needless_collect = "allow"
non_send_fields_in_send_ty = "allow"
redundant_pub_crate = "allow"
significant_drop_in_scrutinee = "allow"
significant_drop_tightening = "allow"
too_long_first_doc_paragraph = "allow"

[workspace.package]
edition = "2021"
version = "0.1.0"
Expand All @@ -15,6 +110,9 @@ license = "MIT"
readme = "README.md"

[workspace.dependencies]
seismic-enclave-derive = { path = "crates/enclave/derive" }
seismic-enclave = { path = "crates/enclave" }

aes-gcm = "0.10"
anyhow = "1.0"
az-tdx-vtpm = "0.7.1"
Expand All @@ -40,5 +138,8 @@ serde_json = "1.0"
sha2 = "0.10"
strum = { version = "0.26", features = ["derive"] }
tokio = { version = "1.44", features = ["full"] }
tracing = { version = "0.1" }
tracing = { version = "0.1"}
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt", "ansi", "json"] }
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
3 changes: 2 additions & 1 deletion crates/enclave-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ name = "seismic_enclave_server"
path = "src/lib.rs"

[dependencies]
seismic-enclave.workspace = true

# attestation-service depends on attestation-agent, ensure versions are compatible when updating
attestation-service = { git = "https://github.com/confidential-containers/trustee", features = ["all-verifier"], rev="1fdd67d"}
attestation-agent = { git = "https://github.com/confidential-containers/guest-components", features = ["az-tdx-vtpm-attester"], rev="e6999a3"}
seismic-enclave = { path = "../enclave" }

aes-gcm.workspace = true
anyhow.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ name = "seismic_enclave"
path = "src/lib.rs"

[dependencies]
seismic-enclave-derive.workspace = true

aes-gcm.workspace = true
anyhow.workspace = true
bincode.workspace = true
Expand Down
18 changes: 18 additions & 0 deletions crates/enclave/derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "seismic-enclave-derive"
version.workspace = true
edition.workspace = true
repository.workspace = true
homepage.workspace = true
authors.workspace = true
license.workspace = true
readme.workspace = true
description = "Tools for building and interfacing with the Seismic enclave"

[lib]
proc-macro = true

[dependencies]
proc-macro2.workspace = true
quote.workspace = true
syn = { version = "2.0", features = ["full"] }
53 changes: 53 additions & 0 deletions crates/enclave/derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemTrait, ReturnType, TraitItem};

/// Derive a sync client from an async rpc trait.
#[proc_macro_attribute]
pub fn derive_sync_client_trait(_attr: TokenStream, item: TokenStream) -> TokenStream {
let input = parse_macro_input!(item as ItemTrait);
let trait_name = &input.ident;
let sync_trait_name = syn::Ident::new(&format!("Sync{}Client", trait_name), trait_name.span());

let methods = input.items.iter().filter_map(|item| {
if let TraitItem::Fn(m) = item {
let sig = &m.sig;
let method_name = &sig.ident;
let inputs = &sig.inputs;
match &sig.output {

ReturnType::Type(_, ty) =>{
if let syn::Type::Path(type_path) = &**ty {
if let Some(segment) = type_path.path.segments.last() {
if segment.ident == "RpcResult" {
if let syn::PathArguments::AngleBracketed(args) = &segment.arguments {
if let Some(syn::GenericArgument::Type(inner_ty)) = args.args.first() {
return Some(quote! {
fn #method_name(#inputs) -> Result<#inner_ty, jsonrpsee::core::client::Error>;
})
}
}
}
}
}
panic!("Method {} has an invalid return type. Return type must be RpcResult<T>", method_name);
}
_ => {
panic!("Method {} has an invalid return type. Return type must be RpcResult<T>", method_name);
}
}
} else {
None
}
});

let expanded = quote! {
pub trait #sync_trait_name {
#(#methods)*
}

#input // Keep the original async trait unchanged
};

TokenStream::from(expanded)
}
Loading