summaryrefslogtreecommitdiffstats
path: root/src/configuration/uapi/set.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-13 15:30:16 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-13 15:30:16 +0100
commita85725eede89f8d7fecd10dc0628a01e48cccd7d (patch)
tree2ac1b7473b95b0791552988b6f9b6294675348f2 /src/configuration/uapi/set.rs
parentWork on UAPI serialize device (diff)
downloadwireguard-rs-a85725eede89f8d7fecd10dc0628a01e48cccd7d.tar.xz
wireguard-rs-a85725eede89f8d7fecd10dc0628a01e48cccd7d.zip
Initial version of full UAPI parser
Diffstat (limited to '')
-rw-r--r--src/configuration/uapi/set.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs
index c609d83..4c2c554 100644
--- a/src/configuration/uapi/set.rs
+++ b/src/configuration/uapi/set.rs
@@ -13,12 +13,19 @@ enum ParserState {
Interface,
}
-struct LineParser<C: Configuration> {
- config: C,
+pub struct LineParser<'a, C: Configuration> {
+ config: &'a C,
state: ParserState,
}
-impl<C: Configuration> LineParser<C> {
+impl<'a, C: Configuration> LineParser<'a, C> {
+ pub fn new(config: &'a C) -> LineParser<'a, C> {
+ LineParser {
+ config,
+ state: ParserState::Interface,
+ }
+ }
+
fn new_peer(value: &str) -> Result<ParserState, ConfigError> {
match <[u8; 32]>::from_hex(value) {
Ok(pk) => Ok(ParserState::Peer {
@@ -29,7 +36,7 @@ impl<C: Configuration> LineParser<C> {
}
}
- fn parse_line(&mut self, key: &str, value: &str) -> Option<ConfigError> {
+ pub fn parse_line(&mut self, key: &str, value: &str) -> Result<(), ConfigError> {
// add the peer if not update_only
let flush_peer = |st: ParserState| -> ParserState {
match st {
@@ -48,7 +55,7 @@ impl<C: Configuration> LineParser<C> {
};
// parse line and update parser state
- match self.state {
+ self.state = match self.state {
// configure the interface
ParserState::Interface => match key {
// opt: set private key
@@ -199,8 +206,8 @@ impl<C: Configuration> LineParser<C> {
// unknown key
_ => Err(ConfigError::InvalidKey),
},
- }
- .map(|st| self.state = st)
- .err()
+ }?;
+
+ Ok(())
}
}