Work on UAPI serialize device

This commit is contained in:
Mathias Hall-Andersen
2019-11-11 23:13:46 +01:00
parent 2ff044dda9
commit 5b555a2e17
6 changed files with 113 additions and 17 deletions

View File

@@ -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")),

View File

@@ -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()) {