Package com.wireguard.config
Class Config
- java.lang.Object
-
- com.wireguard.config.Config
-
public final class Config extends java.lang.ObjectRepresents 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 classConfig.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)InterfacegetInterface()Returns the interface section of the configuration.java.util.List<Peer>getPeers()Returns a list of the configuration's peer sections.inthashCode()static Configparse(java.io.BufferedReader reader)Parses an series of "Interface" and "Peer" sections into aConfig.static Configparse(java.io.InputStream stream)Parses an series of "Interface" and "Peer" sections into aConfig.java.lang.StringtoString()Converts theConfiginto a string suitable for debugging purposes.java.lang.StringtoWgQuickString()Converts theConfiginto a string suitable for use as awg-quickconfiguration file.java.lang.StringtoWgUserspaceString()Serializes theConfigfor 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. ThrowsBadConfigExceptionif 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
Configinstance representing the supplied configuration - Throws:
java.io.IOExceptionBadConfigException
-
parse
public static Config parse(java.io.BufferedReader reader) throws java.io.IOException, BadConfigException
Parses an series of "Interface" and "Peer" sections into aConfig. ThrowsBadConfigExceptionif 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
Configinstance representing the supplied configuration - Throws:
java.io.IOExceptionBadConfigException
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin 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
Peers
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Converts theConfiginto a string suitable for debugging purposes. TheConfigis identified by its interface's public key and the number of peers it has.- Overrides:
toStringin classjava.lang.Object- Returns:
- a concise single-line identifier for the
Config
-
toWgQuickString
public java.lang.String toWgQuickString()
Converts theConfiginto a string suitable for use as awg-quickconfiguration file.- Returns:
- the
Configrepresented as one [Interface] and zero or more [Peer] sections
-
toWgUserspaceString
public java.lang.String toWgUserspaceString()
Serializes theConfigfor use with the WireGuard cross-platform userspace API.- Returns:
- the
Configrepresented as a series of "key=value" lines
-
-