Skip to content

Commit f6a3c06

Browse files
committed
Add Signal protobuf files and compile them to Rust.
It would be cleaner to yield the compiled files OUT_DIR, but that gets ugly very fast because of rust-lang/rust#48250.
1 parent 4712e0b commit f6a3c06

File tree

10 files changed

+583
-0
lines changed

10 files changed

+583
-0
lines changed

libsignal-service/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/proto/*.rs

libsignal-service/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ failure = "0.1.5"
1212
async-trait = "0.1.30"
1313
url = "2.1.1"
1414
thiserror = "1.0"
15+
serde = {version = "1.0", features=["derive"]}
16+
serde_json = "1.0"
17+
protobuf = "2.0.0"
1518

1619
[dev-dependencies]
1720
structopt = "0.2.17"
1821
tokio = { version = "0.2", features=["macros"] }
22+
23+
[build-dependencies]
24+
protoc-rust = "2.0"

libsignal-service/build.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::path::Path;
2+
3+
use protoc_rust::Customize;
4+
5+
fn main() {
6+
let protobuf = Path::new(env!("CARGO_MANIFEST_DIR")).join("protobuf");
7+
8+
let input: Vec<_> = protobuf
9+
.read_dir()
10+
.expect("protobuf directory")
11+
.filter_map(|entry| {
12+
let entry = entry.expect("readable protobuf directory");
13+
let path = entry.path();
14+
if Some("proto")
15+
== path.extension().and_then(std::ffi::OsStr::to_str)
16+
{
17+
assert!(path.is_file());
18+
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
19+
Some(path.to_str().unwrap().to_string())
20+
} else {
21+
None
22+
}
23+
})
24+
.collect();
25+
26+
let input: Vec<&str> = input.iter().map(String::as_ref).collect();
27+
28+
protoc_rust::run(protoc_rust::Args {
29+
out_dir: "src/proto",
30+
input: &input,
31+
includes: &[protobuf.to_str().unwrap()],
32+
customize: Customize {
33+
..Default::default()
34+
},
35+
})
36+
.expect("protoc");
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (C) 2014-2016 Open Whisper Systems
3+
*
4+
* Licensed according to the LICENSE file in this repository.
5+
*/
6+
syntax = "proto2";
7+
8+
package signalservice;
9+
10+
option java_package = "org.whispersystems.signalservice.internal.push";
11+
option java_outer_classname = "ProvisioningProtos";
12+
13+
message ProvisionEnvelope {
14+
optional bytes publicKey = 1;
15+
optional bytes body = 2; // Encrypted ProvisionMessage
16+
}
17+
18+
message ProvisionMessage {
19+
optional bytes identityKeyPublic = 1;
20+
optional bytes identityKeyPrivate = 2;
21+
optional string number = 3;
22+
optional string uuid = 8;
23+
optional string provisioningCode = 4;
24+
optional string userAgent = 5;
25+
optional bytes profileKey = 6;
26+
optional bool readReceipts = 7;
27+
optional uint32 provisioningVersion = 9;
28+
}
29+
30+
enum ProvisioningVersion {
31+
option allow_alias = true;
32+
33+
INITIAL = 0;
34+
TABLET_SUPPORT = 1;
35+
CURRENT = 1;
36+
}

0 commit comments

Comments
 (0)