Package org.tinyradius.packet.util
Class PacketCodec
java.lang.Object
org.tinyradius.packet.util.PacketCodec
public class PacketCodec
extends java.lang.Object
To encode/decode packets to/from Datagram.
A dictionary is required in constructor to avoid passing in dictionary on every conversion - in typical use cases, only one instance of this class will be required as the server/proxy/client will be using one Dictionary.
-
Method Summary
Modifier and Type Method Description static RadiusRequest
fromDatagramRequest(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram)
Reads a request from the given input stream and creates an appropriate RadiusPacket/subclass.static RadiusResponse
fromDatagramResponse(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram)
Reads a response from the given input stream and creates an appropriate RadiusPacket/subclass.static io.netty.buffer.ByteBuf
toByteBuf(RadiusPacket packet)
static io.netty.channel.socket.DatagramPacket
toDatagram(RadiusPacket packet, java.net.InetSocketAddress recipient)
static io.netty.channel.socket.DatagramPacket
toDatagram(RadiusPacket packet, java.net.InetSocketAddress recipient, java.net.InetSocketAddress sender)
-
Method Details
-
toDatagram
public static io.netty.channel.socket.DatagramPacket toDatagram(RadiusPacket packet, java.net.InetSocketAddress recipient) throws RadiusPacketException- Parameters:
packet
- packet to convertrecipient
- destination socket- Returns:
- converted DatagramPacket
- Throws:
RadiusPacketException
- if packet could not be encoded/serialized to datagram
-
toDatagram
public static io.netty.channel.socket.DatagramPacket toDatagram(RadiusPacket packet, java.net.InetSocketAddress recipient, java.net.InetSocketAddress sender) throws RadiusPacketException- Parameters:
packet
- packet to convertrecipient
- destination socketsender
- source socket, nullable- Returns:
- converted DatagramPacket
- Throws:
RadiusPacketException
- if packet could not be encoded/serialized to datagram
-
toByteBuf
- Throws:
RadiusPacketException
-
fromDatagramRequest
public static RadiusRequest fromDatagramRequest(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram) throws RadiusPacketExceptionReads a request from the given input stream and creates an appropriate RadiusPacket/subclass.Decodes the encrypted fields and attributes of the packet, and checks authenticator if appropriate.
- Parameters:
dictionary
- dictionary to use for attributesdatagram
- DatagramPacket to read packet from- Returns:
- new RadiusPacket object
- Throws:
RadiusPacketException
- malformed packet
-
fromDatagramResponse
public static RadiusResponse fromDatagramResponse(Dictionary dictionary, io.netty.channel.socket.DatagramPacket datagram) throws RadiusPacketExceptionReads a response from the given input stream and creates an appropriate RadiusPacket/subclass.Decodes the encrypted fields and attributes of the packet, and checks authenticator if appropriate.
- Parameters:
dictionary
- dictionary to use for attributesdatagram
- DatagramPacket to read packet from- Returns:
- new RadiusPacket object
- Throws:
RadiusPacketException
- malformed packet
-