Skip to content

Commit b661fe0

Browse files
authored
Merge pull request #117 from hug-dev/protobuf-generated
Commit the generated Rust protobuf files in tree
2 parents c64624d + 7ca41ab commit b661fe0

35 files changed

+891
-45
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ categories = ["encoding"]
1111
edition = "2018"
1212

1313
[build-dependencies]
14-
prost-build = "0.6.1"
14+
prost-build = { version = "0.6.1", optional = true }
1515

1616
[dependencies]
1717
serde = { version = "1.0.115", features = ["derive"] }
@@ -31,3 +31,4 @@ derivative = "2.1.1"
3131
[features]
3232
testing = []
3333
fuzz = ["arbitrary"]
34+
regenerate-protobuf = ["prost-build"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ trying to compile otherwise it will not work ("`No such file or directory`").
1717
$ git submodule update --init
1818
```
1919

20+
By default, the crate will use the pre-generated Rust Protobuf files in
21+
`src/operations_protobuf/generated_ops`. To re-generate them from the `parsec-operations`
22+
submodule, compile this
23+
crate with the feature `regenerate-protobuf`.
24+
2025
## License
2126

2227
The software is provided under Apache-2.0. Contributions to this project are accepted under the same license.

build.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
// This one is hard to avoid.
55
#![allow(clippy::multiple_crate_versions)]
66

7-
use std::fs::read_dir;
8-
use std::io::{Error, ErrorKind, Result};
9-
use std::path::Path;
7+
use std::io::Result;
108

9+
// Replace the committed protobuf files with the generated one.
10+
#[cfg(feature = "regenerate-protobuf")]
1111
fn generate_proto_sources() -> Result<()> {
12+
use std::fs::read_dir;
13+
use std::io::{Error, ErrorKind};
14+
use std::path::Path;
15+
use std::process::Command;
16+
1217
let path = String::from("parsec-operations/protobuf");
1318
let dir_entries = read_dir(Path::new(&path))?;
1419
let files: Result<Vec<String>> = dir_entries
@@ -31,9 +36,31 @@ fn generate_proto_sources() -> Result<()> {
3136
.filter(|string| string.ends_with(".proto"))
3237
.collect();
3338
let files_slices: Vec<&str> = proto_files.iter().map(|file| &file[..]).collect();
34-
prost_build::compile_protos(&files_slices, &[&path])
39+
40+
prost_build::compile_protos(&files_slices, &[&path])?;
41+
42+
// Copy all files generated in src/operations_protobuf/generated_ops
43+
let status = Command::new("bash")
44+
.arg("-c")
45+
.arg(format!(
46+
"cp {}/*.rs src/operations_protobuf/generated_ops",
47+
std::env::var("OUT_DIR").expect("OUT_DIR env var is empty")
48+
))
49+
.status()?;
50+
51+
if !status.success() {
52+
Err(Error::new(
53+
ErrorKind::InvalidData,
54+
"failed copying generated protobuf files",
55+
))
56+
} else {
57+
Ok(())
58+
}
3559
}
3660

3761
fn main() -> Result<()> {
38-
generate_proto_sources()
62+
#[cfg(feature = "regenerate-protobuf")]
63+
generate_proto_sources()?;
64+
65+
Ok(())
3966
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct Operation {
3+
#[prost(string, tag="1")]
4+
pub client: std::string::String,
5+
}
6+
#[derive(Clone, PartialEq, ::prost::Message)]
7+
pub struct Result {
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct AuthenticatorInfo {
3+
#[prost(string, tag="1")]
4+
pub description: std::string::String,
5+
#[prost(uint32, tag="2")]
6+
pub version_maj: u32,
7+
#[prost(uint32, tag="3")]
8+
pub version_min: u32,
9+
#[prost(uint32, tag="4")]
10+
pub version_rev: u32,
11+
#[prost(uint32, tag="5")]
12+
pub id: u32,
13+
}
14+
#[derive(Clone, PartialEq, ::prost::Message)]
15+
pub struct Operation {
16+
}
17+
#[derive(Clone, PartialEq, ::prost::Message)]
18+
pub struct Result {
19+
#[prost(message, repeated, tag="1")]
20+
pub authenticators: ::std::vec::Vec<AuthenticatorInfo>,
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct Operation {
3+
}
4+
#[derive(Clone, PartialEq, ::prost::Message)]
5+
pub struct Result {
6+
#[prost(string, repeated, tag="1")]
7+
pub clients: ::std::vec::Vec<std::string::String>,
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct KeyInfo {
3+
#[prost(uint32, tag="1")]
4+
pub provider_id: u32,
5+
#[prost(string, tag="2")]
6+
pub name: std::string::String,
7+
#[prost(message, optional, tag="3")]
8+
pub attributes: ::std::option::Option<super::psa_key_attributes::KeyAttributes>,
9+
}
10+
#[derive(Clone, PartialEq, ::prost::Message)]
11+
pub struct Operation {
12+
}
13+
#[derive(Clone, PartialEq, ::prost::Message)]
14+
pub struct Result {
15+
#[prost(message, repeated, tag="1")]
16+
pub keys: ::std::vec::Vec<KeyInfo>,
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct Operation {
3+
#[prost(uint32, tag="1")]
4+
pub provider_id: u32,
5+
}
6+
#[derive(Clone, PartialEq, ::prost::Message)]
7+
pub struct Result {
8+
#[prost(uint32, repeated, tag="1")]
9+
pub opcodes: ::std::vec::Vec<u32>,
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct ProviderInfo {
3+
#[prost(string, tag="1")]
4+
pub uuid: std::string::String,
5+
#[prost(string, tag="2")]
6+
pub description: std::string::String,
7+
#[prost(string, tag="3")]
8+
pub vendor: std::string::String,
9+
#[prost(uint32, tag="4")]
10+
pub version_maj: u32,
11+
#[prost(uint32, tag="5")]
12+
pub version_min: u32,
13+
#[prost(uint32, tag="6")]
14+
pub version_rev: u32,
15+
#[prost(uint32, tag="7")]
16+
pub id: u32,
17+
}
18+
#[derive(Clone, PartialEq, ::prost::Message)]
19+
pub struct Operation {
20+
}
21+
#[derive(Clone, PartialEq, ::prost::Message)]
22+
pub struct Result {
23+
#[prost(message, repeated, tag="1")]
24+
pub providers: ::std::vec::Vec<ProviderInfo>,
25+
}

src/operations_protobuf/generated_ops.rs renamed to src/operations_protobuf/generated_ops/mod.rs

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,34 @@
11
// Copyright 2020 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
3-
// Include the Rust generated file in its own module.
4-
use zeroize::Zeroize;
53

6-
macro_rules! include_protobuf_as_module {
7-
($name:ident) => {
8-
pub mod $name {
9-
#[allow(unused)]
10-
#[macro_export]
11-
use zeroize::Zeroize;
12-
// The generated Rust file is in OUT_DIR, named $name.rs
13-
include!(concat!(env!("OUT_DIR"), "/", stringify!($name), ".rs"));
14-
}
15-
};
16-
}
4+
pub mod psa_sign_hash;
5+
pub mod psa_verify_hash;
6+
pub mod psa_sign_message;
7+
pub mod psa_verify_message;
8+
pub mod psa_asymmetric_encrypt;
9+
pub mod psa_asymmetric_decrypt;
10+
pub mod psa_aead_encrypt;
11+
pub mod psa_aead_decrypt;
12+
pub mod psa_generate_key;
13+
pub mod psa_destroy_key;
14+
pub mod psa_export_public_key;
15+
pub mod psa_export_key;
16+
pub mod psa_import_key;
17+
pub mod list_opcodes;
18+
pub mod list_providers;
19+
pub mod list_authenticators;
20+
pub mod list_keys;
21+
pub mod list_clients;
22+
pub mod delete_client;
23+
pub mod ping;
24+
pub mod psa_key_attributes;
25+
pub mod psa_algorithm;
26+
pub mod psa_generate_random;
27+
pub mod psa_hash_compute;
28+
pub mod psa_hash_compare;
29+
pub mod psa_raw_key_agreement;
1730

18-
include_protobuf_as_module!(psa_sign_hash);
19-
include_protobuf_as_module!(psa_verify_hash);
20-
include_protobuf_as_module!(psa_sign_message);
21-
include_protobuf_as_module!(psa_verify_message);
22-
include_protobuf_as_module!(psa_asymmetric_encrypt);
23-
include_protobuf_as_module!(psa_asymmetric_decrypt);
24-
include_protobuf_as_module!(psa_aead_encrypt);
25-
include_protobuf_as_module!(psa_aead_decrypt);
26-
include_protobuf_as_module!(psa_generate_key);
27-
include_protobuf_as_module!(psa_destroy_key);
28-
include_protobuf_as_module!(psa_export_public_key);
29-
include_protobuf_as_module!(psa_export_key);
30-
include_protobuf_as_module!(psa_import_key);
31-
include_protobuf_as_module!(list_opcodes);
32-
include_protobuf_as_module!(list_providers);
33-
include_protobuf_as_module!(list_authenticators);
34-
include_protobuf_as_module!(list_keys);
35-
include_protobuf_as_module!(list_clients);
36-
include_protobuf_as_module!(delete_client);
37-
include_protobuf_as_module!(ping);
38-
include_protobuf_as_module!(psa_key_attributes);
39-
include_protobuf_as_module!(psa_algorithm);
40-
include_protobuf_as_module!(psa_generate_random);
41-
include_protobuf_as_module!(psa_hash_compute);
42-
include_protobuf_as_module!(psa_hash_compare);
43-
include_protobuf_as_module!(psa_raw_key_agreement);
31+
use zeroize::Zeroize;
4432

4533
use crate::requests::{ResponseStatus, Result};
4634
use log::error;

0 commit comments

Comments
 (0)