Package com.wireguard.config
Class Config
- java.lang.Object
-
- com.wireguard.config.Config
-
public final class Config extends java.lang.Object
Represents the contents of a wg-quick configuration file, made up of one or more "Interface" sections (combined together), and zero or more "Peer" sections (treated individually).Instances of this class are immutable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Config.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
Interface
getInterface()
Returns the interface section of the configuration.java.util.List<Peer>
getPeers()
Returns a list of the configuration's peer sections.int
hashCode()
static Config
parse(java.io.BufferedReader reader)
Parses an series of "Interface" and "Peer" sections into aConfig
.static Config
parse(java.io.InputStream stream)
Parses an series of "Interface" and "Peer" sections into aConfig
.java.lang.String
toString()
Converts theConfig
into a string suitable for debugging purposes.java.lang.String
toWgQuickString()
Converts theConfig
into a string suitable for use as awg-quick
configuration file.java.lang.String
toWgUserspaceString()
Serializes theConfig
for use with the WireGuard cross-platform userspace API.
-
-
-
Method Detail
-
parse
public static Config parse(java.io.InputStream stream) throws java.io.IOException, BadConfigException
Parses an series of "Interface" and "Peer" sections into aConfig
. ThrowsBadConfigException
if the input is not well-formed or contains data that cannot be parsed.- Parameters:
stream
- a stream of UTF-8 text that is interpreted as a WireGuard configuration- Returns:
- a
Config
instance representing the supplied configuration - Throws:
java.io.IOException
BadConfigException
-
parse
public static Config parse(java.io.BufferedReader reader) throws java.io.IOException, BadConfigException
Parses an series of "Interface" and "Peer" sections into aConfig
. ThrowsBadConfigException
if the input is not well-formed or contains data that cannot be parsed.- Parameters:
reader
- a BufferedReader of UTF-8 text that is interpreted as a WireGuard configuration- Returns:
- a
Config
instance representing the supplied configuration - Throws:
java.io.IOException
BadConfigException
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getInterface
public Interface getInterface()
Returns the interface section of the configuration.- Returns:
- the interface configuration
-
getPeers
public java.util.List<Peer> getPeers()
Returns a list of the configuration's peer sections.- Returns:
- a list of
Peer
s
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Converts theConfig
into a string suitable for debugging purposes. TheConfig
is identified by its interface's public key and the number of peers it has.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a concise single-line identifier for the
Config
-
toWgQuickString
public java.lang.String toWgQuickString()
Converts theConfig
into a string suitable for use as awg-quick
configuration file.- Returns:
- the
Config
represented as one [Interface] and zero or more [Peer] sections
-
toWgUserspaceString
public java.lang.String toWgUserspaceString()
Serializes theConfig
for use with the WireGuard cross-platform userspace API.- Returns:
- the
Config
represented as a series of "key=value" lines
-
-