#wireguard #builder #amnezia

wireguard-conf

Construct Wireguard's interface and peer configs

1 unstable release

new 0.1.0 Feb 15, 2025

#579 in Cryptography

Download history 105/week @ 2025-02-11

105 downloads per month

MIT license

19KB
321 lines

Wireguard Conf

Easy to use library for creating wireguard configs.

Installation

Install wireguard-conf and ipnet (for parsing ip networks)

cargo add wireguard-conf ipnet

Usage

More usage examples in tests and on docs.rs

use wireguard_conf::prelude::*;
use wireguard_conf::as_ipnet;

use ipnet::Ipv4Net;

// create peer:
let peer = PeerBuilder::new()
    .add_allowed_ip(as_ipnet!("10.0.0.2/24"))
    .build();

// create interface with that peer:
let interface = InterfaceBuilder::new()
    .address(as_ipnet!("10.0.0.1/24"))
    .add_peer(peer.clone())
    .build();

// to export configs, use `println!()`, `writeln!()`, `.to_string()`, etc.

println!("Server's config:");
println!("{}\n", interface);

println!("Client's config:");
println!("{}", peer.to_interface(&interface).unwrap());

lib.rs:

Easy to use Wireguard config generator.

Example

use wireguard_conf::prelude::*;
use wireguard_conf::as_ipnet;

use ipnet::Ipv4Net;

let peer = PeerBuilder::new()
    .add_allowed_ip(as_ipnet!("10.0.0.2/24"))
    .build();

let interface = InterfaceBuilder::new()
    .address(as_ipnet!("10.0.0.1/24"))
    .add_peer(peer.clone())
    .build();

// to export configs, use `println!()`, `writeln!()`, `.to_string()`, etc.

println!("Server's config:");
println!("{}\n", interface);

println!("Client's config:");
println!("{}", peer.to_interface(&interface).unwrap());

Dependencies

~2–3MB
~66K SLoC