rm Cargo.lock for lib; add sha512 check to build fetch; typo

This commit is contained in:
Dan Ballard 2022-01-17 18:24:58 -05:00
parent 2d4e7bb751
commit 81fbfdd151
6 changed files with 26 additions and 187 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/target
.idea
example_cwtch_dir
Cargo.lock

179
Cargo.lock generated
View File

@ -1,179 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "darling"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "libc"
version = "0.2.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
[[package]]
name = "libcwtch"
version = "0.1.0"
dependencies = [
"libc",
"serde",
"serde_json",
"serde_with",
]
[[package]]
name = "proc-macro2"
version = "1.0.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustversion"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
version = "1.0.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f03b9878abf6d14e6779d3f24f07b2cfa90352cfec4acc5aab8f1ac7f146fae8"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a024926d3432516606328597e0f224a51355a493b49fdd67e9209187cbe55ecc"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_with"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "062b87e45d8f26714eacfaef0ed9a583e2bfd50ebd96bdd3c200733bd5758e2c"
dependencies = [
"rustversion",
"serde",
"serde_with_macros",
]
[[package]]
name = "serde_with_macros"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98c1fcca18d55d1763e1c16873c4bde0ac3ef75179a28c7b372917e0494625be"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

View File

@ -9,8 +9,12 @@ repository = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs"
readme = "README.md"
documentation = "https://docs.rs/libcwtch/0.1.0/libcwtch/"
[build-dependencies]
hex-literal = "0.3.4"
sha2 = "0.10.1"
[dependencies]
libc = "0.2"
serde_json = "1.0"
serde = { version = "1.0.127", features = ["derive"] }
serde_with = { version = "1.10.0" }
serde_with = { version = "1.10.0" }

View File

@ -1,6 +1,10 @@
use std::env;
use std::fs;
use std::path::Path;
use std::process::Command;
use std::{env, io};
use hex_literal::hex;
use sha2::{Digest, Sha512};
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
@ -18,4 +22,12 @@ fn main() {
.arg(lib_cwtch_path)
.output()
.expect("failed to download libCwtch.so");
let lib_cwtch_path = Path::new(&out_dir).join("libCwtch.so");
let mut hasher = Sha512::new();
let mut file = fs::File::open(&lib_cwtch_path).expect("could not open lib to hash");
io::copy(&mut file, &mut hasher).expect("failed to copy file into hasher");
let hash_bytes = hasher.finalize();
assert_eq!(hash_bytes[..], hex!("776a26076dfad3370d1b2edec9ad954187584f54483ec201163be0dc356c10b0fe74168e8e95f2116f458e5676e1fb07fbd0357cab1e4389ac762fe03bd5ef67")[..]);
}

View File

@ -7,6 +7,7 @@ use libcwtch::CwtchLib;
fn main() {
let bot_home = "example_cwtch_dir";
match std::fs::remove_dir_all(&bot_home) {
// this will always error on first run as we haven't created the directory, it's just a function to clear it on successive runs, so this error is to be ignored
_ => (),
}
std::fs::create_dir_all(&bot_home).expect("Error creating bot_home directory");
@ -44,7 +45,7 @@ fn main() {
&event.data["ServerList"],
) {
Ok(p) => p,
Err(e) => panic!("error parsing profile: {}", e)
Err(e) => panic!("error parsing profile: {}", e),
};
print!("profile: {:?}", profile);
}

View File

@ -120,13 +120,13 @@ impl Profile {
contacts_json: &str,
server_list: &str,
) -> Result<Profile, String> {
let contacts = match Profile::process_contacts(contacts_json){
let contacts = match Profile::process_contacts(contacts_json) {
Ok(c) => c,
Err(e) => return Err(e)
Err(e) => return Err(e),
};
let servers = match Profile::process_servers(server_list) {
Ok(s) => s,
Err(e) => return Err(e)
Err(e) => return Err(e),
};
Ok(Profile {
onion: identity.to_string(),
@ -146,7 +146,7 @@ impl Profile {
println!("contacts_json: '{}'", constacts_json);
let contacts_map: Vec<Contact> = match serde_json::from_str(constacts_json) {
Ok(cm) => cm,
Err(e) => return Err(format!("invalid json: {:?}", e))
Err(e) => return Err(format!("invalid json: {:?}", e)),
};
for contact in contacts_map {
contacts.insert(contact.onion.clone(), contact);
@ -161,7 +161,7 @@ impl Profile {
}
let servers_map: Vec<Server> = match serde_json::from_str(servers_json) {
Ok(sm) => sm,
Err(e) => return Err(format!("invalid jason: {:?}", e))
Err(e) => return Err(format!("invalid json: {:?}", e)),
};
for server in servers_map {
servers.insert(server.onion.clone(), server);