Vecna 3 лет назад
Родитель
Сommit
aa7fae385c
2 измененных файлов с 47 добавлено и 0 удалено
  1. 10 0
      bridge_auth/Cargo.toml
  2. 37 0
      bridge_auth/src/main.rs

+ 10 - 0
bridge_auth/Cargo.toml

@@ -0,0 +1,10 @@
+[package]
+name = "bridge_auth"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+lox = { git = "https://git-crysp.uwaterloo.ca/iang/lox.git" }
+ed25519-dalek = "1"

+ 37 - 0
bridge_auth/src/main.rs

@@ -0,0 +1,37 @@
+use ed25519_dalek::PublicKey;
+use lox::BridgeAuth;
+use std::fs::File;
+use std::io::BufReader;
+use std::io::Read;
+use std::io::Write;
+
+fn main() {
+    // import bridgedb pubkey
+    // note: currently no checks for valid data
+    let infile = std::fs::File::open("../pubkeys/bridgedb_pubkey").unwrap();
+    let mut reader = BufReader::new(infile);
+    let mut buffer = Vec::new();
+    reader
+        .read_to_end(&mut buffer)
+        .expect("Failed to read pubkey from file");
+    let bridgedb_pubkey = PublicKey::from_bytes(&buffer).unwrap();
+
+    // create new bridge authority (implicitly generates keys)
+    let bridge_auth = BridgeAuth::new(bridgedb_pubkey);
+
+    // output public keys to new files
+    // I think this approach is too hacky because it requires multiple
+    // files, one per key...
+    let mut count = 0;
+    // TODO: Figure out how to deal with X being private
+    for pubkey in bridge_auth.lox_pub.X {
+        count += 1;
+        let pubkey_bytes = pubkey.compress().to_bytes();
+        // Is this the proper way to concatenate an integer and a string?
+        let mut outfile = File::create(format!("{}{}", "../pubkeys/bridge_auth_pubkey_", count))
+            .expect("Failed to create pubkey file");
+        outfile
+            .write_all(&pubkey_bytes)
+            .expect("Failed to write pubkey");
+    }
+}