aboutsummaryrefslogtreecommitdiffstats
path: root/src/wireguard
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-11 23:13:46 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-11 23:13:46 +0100
commit5b555a2e176bd5310d2efa614f67c96cb314eda4 (patch)
treeb79cb04b38e052fb8ed63d7212020a1c8a31b6f2 /src/wireguard
parentImplemented UAPI "get" line-parser (diff)
downloadwireguard-rs-5b555a2e176bd5310d2efa614f67c96cb314eda4.tar.xz
wireguard-rs-5b555a2e176bd5310d2efa614f67c96cb314eda4.zip
Work on UAPI serialize device
Diffstat (limited to 'src/wireguard')
-rw-r--r--src/wireguard/handshake/device.rs2
-rw-r--r--src/wireguard/wireguard.rs3
2 files changed, 4 insertions, 1 deletions
diff --git a/src/wireguard/handshake/device.rs b/src/wireguard/handshake/device.rs
index 85c2e45..f65692c 100644
--- a/src/wireguard/handshake/device.rs
+++ b/src/wireguard/handshake/device.rs
@@ -202,7 +202,7 @@ impl Device {
/// A 32 byte array holding the PSK
///
/// The call might fail if the public key is not found
- pub fn get_psk(&self, pk: PublicKey) -> Result<Psk, ConfigError> {
+ pub fn get_psk(&self, pk: &PublicKey) -> Result<Psk, ConfigError> {
match self.pk_map.get(pk.as_bytes()) {
Some(peer) => Ok(peer.psk),
_ => Err(ConfigError::new("No such public key")),
diff --git a/src/wireguard/wireguard.rs b/src/wireguard/wireguard.rs
index a890d5e..77be9f8 100644
--- a/src/wireguard/wireguard.rs
+++ b/src/wireguard/wireguard.rs
@@ -204,6 +204,9 @@ impl<T: Tun, B: Bind> Wireguard<T, B> {
pub fn set_psk(&self, pk: PublicKey, psk: Option<[u8; 32]>) -> bool {
self.state.handshake.write().set_psk(pk, psk).is_ok()
}
+ pub fn get_psk(&self, pk: &PublicKey) -> Option<[u8; 32]> {
+ self.state.handshake.read().get_psk(pk).ok()
+ }
pub fn add_peer(&self, pk: PublicKey) {
if self.state.peers.read().contains_key(pk.as_bytes()) {