use base64 ids

This commit is contained in:
shim_ 2019-01-13 15:31:03 +01:00
parent da029637a1
commit e432793aeb
4 changed files with 33 additions and 10 deletions

View File

@ -1,9 +1,13 @@
FROM rust:1.31.1 AS eventbuild FROM rust:1.31.1 AS eventbuild
COPY wg-event-gen/ /build
WORKDIR /build WORKDIR /build
COPY wg-event-gen/Cargo.* /build/
RUN mkdir -p src && echo "fn main() {}" > src/main.rs && cargo build --release
COPY wg-event-gen/ /build
RUN cargo build --release RUN cargo build --release
FROM golang AS build FROM golang AS build

View File

@ -1,14 +1,30 @@
[[package]] [[package]]
name = "strum" name = "base64"
version = "0.13.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "1.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hex"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "wg-event-gen" name = "wg-event-gen"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"strum 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[metadata] [metadata]
"checksum strum 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f6b3fc98c482ff9bb37a6db6a6491218c4c82bec368bd5682033e5b96b969143" "checksum base64 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "621fc7ecb8008f86d7fb9b95356cd692ce9514b80a86d85b397f32a22da7b9e2"
"checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d"
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"

View File

@ -5,4 +5,5 @@ authors = ["shimun <wg.shimun@shimun.net>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
strum = "0.13.0" hex = "0.3.2"
base64 = "0.10.0"

View File

@ -5,6 +5,8 @@ use crate::gen::*;
use crate::listener::*; use crate::listener::*;
use std::collections::HashMap; use std::collections::HashMap;
use hex;
use base64;
use std::env; use std::env;
use std::fmt; use std::fmt;
use std::io::prelude::*; use std::io::prelude::*;
@ -42,7 +44,7 @@ impl Peer {
None => return Err(Error::new(ErrorKind::Other, "Peer is missing key")), None => return Err(Error::new(ErrorKind::Other, "Peer is missing key")),
}; };
Ok(Peer { Ok(Peer {
public_key: key.to_string(), public_key: base64::encode(&hex::decode(key).unwrap()),
endpoint: entries endpoint: entries
.iter() .iter()
.filter(|(key, _)| key == &"endpoint") .filter(|(key, _)| key == &"endpoint")
@ -77,11 +79,11 @@ impl State {
} }
} }
pub fn id<'a>(&'a self) -> Option<&'a String> { pub fn id<'a>(&'a self) -> Option<String> {
self.kv() self.kv()
.iter() .iter()
.filter(|(key, _)| key == &"private_key" || key == &"public_key") .filter(|(key, _)| key == &"private_key" || key == &"public_key")
.map(|(_, value)| value) .map(|(_, value)| base64::encode(&hex::decode(&value).unwrap()))
.next() .next()
} }