Expand description
Low-level line framing for the OpenVPN management protocol.
This crate provides:
Frame— a classified line from the management interfaceFrameDecoder— a stateless-ishtokio_util::codec::Decoderthat splits the byte stream intoFramevalues- Encoder primitives (
write_line,write_block,wire_safe,escape,quote) for building wire-format commands
The decoder does not track which command was sent — it classifies
each line purely from its content. Multi-line response accumulation
(grouping Line/End sequences) is left to higher layers.
>CLIENT:ENV accumulation is handled here because the protocol
guarantees atomicity for that block and the individual ENV lines are
not meaningful on their own.
§Decoding frames
use bytes::BytesMut;
use tokio_util::codec::Decoder;
use openvpn_mgmt_frame::{Frame, FrameDecoder};
let mut decoder = FrameDecoder::new();
let mut buf = BytesMut::from("SUCCESS: pid=1234\n>HOLD:Waiting for hold release:0\n");
assert_eq!(
decoder.decode(&mut buf).unwrap(),
Some(Frame::Success("pid=1234".to_string())),
);
assert_eq!(
decoder.decode(&mut buf).unwrap(),
Some(Frame::Notification {
kind: "HOLD".to_string(),
payload: "Waiting for hold release:0".to_string(),
}),
);
assert_eq!(decoder.decode(&mut buf).unwrap(), None); // buffer drained§Encoding commands
use bytes::BytesMut;
use openvpn_mgmt_frame::{write_line, write_block, escape, quote, EncoderMode};
let mut buf = BytesMut::new();
write_line(&mut buf, "status 3");
assert_eq!(&buf[..], b"status 3\n");
buf.clear();
write_block(&mut buf, "client-auth 1 2", &["push-reply".to_string()], EncoderMode::Sanitize).unwrap();
assert_eq!(&buf[..], b"client-auth 1 2\npush-reply\nEND\n");Structs§
- Frame
Decoder - A low-level decoder that splits the byte stream into
Framevalues.
Enums§
- Accumulation
Limit - Controls how many items the decoder will accumulate before returning an error.
- Encode
Error - Structured error for encoder-side validation failures.
- Encoder
Mode - Controls how the encoder handles characters that are unsafe for the
line-oriented management protocol (
\n,\r,\0). - Frame
- A classified line (or accumulated block) from the OpenVPN management interface.
Functions§
- escape
- Backslash-escape
\and"per the OpenVPN config-file lexer rules. - quote
- Wrap an already-escaped string in double quotes.
- wire_
safe - Ensure a string is safe for the wire protocol.
- write_
block - Write a multi-line block: header line, body lines, and a terminating
END. - write_
line - Write a single line followed by
\n.