2 releases

0.1.1 Jun 6, 2022
0.1.0 Mar 31, 2022

#1892 in Parser implementations

Download history 27/week @ 2024-07-19 54/week @ 2024-07-26 40/week @ 2024-08-02 46/week @ 2024-08-09 52/week @ 2024-08-16 42/week @ 2024-08-23 123/week @ 2024-08-30 58/week @ 2024-09-06 31/week @ 2024-09-13 46/week @ 2024-09-20 89/week @ 2024-09-27 80/week @ 2024-10-04 19/week @ 2024-10-11 42/week @ 2024-10-18 15/week @ 2024-10-25 42/week @ 2024-11-01

120 downloads per month
Used in 2 crates

AGPL-3.0-only

21KB
436 lines

WireGuard Keys

This is a utility crate containing data structures relating to WireGuard. There are no builds for it, but the RustDoc documentation is published on every commit.

Resources:

To build this, you want to run make setup-git because it will use your SSH keys instead of asking for git credentials (and possibly requiring 2-factor authentication).

Features

By default, this crate only provides types for WireGuard keys (Pubkey, Privkey, Secret). These optional features can be enabled:

  • serde: serialization and deserialization capabilities (enabled by default).
  • hex: convert to and from hex (enabled by default).
  • base64: convert to and from base64 (enabled by default).
  • base32: convert to and from base32.
  • rocket: ability to parse WireGuard keys from HTTP requests in Rocket.
  • schema: ability to generate JSON schemas from the types.

lib.rs:

This crate allows for working with WireGuard keys. WireGuard uses asymmetric x25519 keys, which are represented by the [Privkey] and [Pubkey] types respectively. Private keys can be generated randomly, and their corresponding public key can be derived. Additionally, WireGuard allows using a preshared key as additional security layer, which is just a random 256-bit value. This is represented by the [Secret] type.

For security reasons, this crate uses the [Zeroize] trait to mark all types containing cryyptographically relevant information to be cleared on drop. The [x25519_dalek_fiat] crate is used for x25519 operations.

This crate allows for encoding keys in various ways. The crate supports base64, which is typically used by WireGuard, but hex and base32 can be enabled as well. Enabling encodings also enables parsing from that encoding.

The [serde] feature, which is enabled by default, adds serialize and deserialize support for WireGuard types. How these types are serialized depends on the format: when serializing into human-readable formats, such as JSON, the keys are serialized as base64-encoded strings. However, when serializing to binary formats such as Bincode, keys are serialized as raw bytes.

The optional schema feature adds information to the types allowing to generate JSON schema from them automatically using schemars.

Enabling the rocket feature adds the ability to parse any WireGuard types from a HTTP request using the FromParam trait.

Dependencies

~2–33MB
~532K SLoC