Skip to content

Commit

Permalink
Add Signal protobuf files and compile them to Rust.
Browse files Browse the repository at this point in the history
It would be cleaner to yield the compiled files OUT_DIR, but that gets
ugly very fast because of
rust-lang/rust#48250.
  • Loading branch information
rubdos committed Jun 18, 2020
1 parent 4712e0b commit f6a3c06
Show file tree
Hide file tree
Showing 10 changed files with 583 additions and 0 deletions.
1 change: 1 addition & 0 deletions libsignal-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/proto/*.rs
6 changes: 6 additions & 0 deletions libsignal-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ failure = "0.1.5"
async-trait = "0.1.30"
url = "2.1.1"
thiserror = "1.0"
serde = {version = "1.0", features=["derive"]}
serde_json = "1.0"
protobuf = "2.0.0"

[dev-dependencies]
structopt = "0.2.17"
tokio = { version = "0.2", features=["macros"] }

[build-dependencies]
protoc-rust = "2.0"
37 changes: 37 additions & 0 deletions libsignal-service/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::path::Path;

use protoc_rust::Customize;

fn main() {
let protobuf = Path::new(env!("CARGO_MANIFEST_DIR")).join("protobuf");

let input: Vec<_> = protobuf
.read_dir()
.expect("protobuf directory")
.filter_map(|entry| {
let entry = entry.expect("readable protobuf directory");
let path = entry.path();
if Some("proto")
== path.extension().and_then(std::ffi::OsStr::to_str)
{
assert!(path.is_file());
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
Some(path.to_str().unwrap().to_string())
} else {
None
}
})
.collect();

let input: Vec<&str> = input.iter().map(String::as_ref).collect();

protoc_rust::run(protoc_rust::Args {
out_dir: "src/proto",
input: &input,
includes: &[protobuf.to_str().unwrap()],
customize: Customize {
..Default::default()
},
})
.expect("protoc");
}
36 changes: 36 additions & 0 deletions libsignal-service/protobuf/Provisioning.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2014-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/
syntax = "proto2";

package signalservice;

option java_package = "org.whispersystems.signalservice.internal.push";
option java_outer_classname = "ProvisioningProtos";

message ProvisionEnvelope {
optional bytes publicKey = 1;
optional bytes body = 2; // Encrypted ProvisionMessage
}

message ProvisionMessage {
optional bytes identityKeyPublic = 1;
optional bytes identityKeyPrivate = 2;
optional string number = 3;
optional string uuid = 8;
optional string provisioningCode = 4;
optional string userAgent = 5;
optional bytes profileKey = 6;
optional bool readReceipts = 7;
optional uint32 provisioningVersion = 9;
}

enum ProvisioningVersion {
option allow_alias = true;

INITIAL = 0;
TABLET_SUPPORT = 1;
CURRENT = 1;
}
Loading

0 comments on commit f6a3c06

Please sign in to comment.