mostly parsing eavp extensions

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer
2025-05-24 02:13:35 +02:00
parent fb01a117ad
commit f1101e0c01
4 changed files with 48 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package peap
import (
"encoding/binary"
"fmt"
)
type AVPType uint16
@ -10,6 +11,8 @@ const (
AVPAckResult AVPType = 3
)
const ExtensionHeaderSize = 4
type ExtensionAVP struct {
Mandatory bool
Type AVPType // 14-bit field
@ -17,6 +20,22 @@ type ExtensionAVP struct {
Value []byte
}
func (eavp *ExtensionAVP) Decode(raw []byte) error {
typ := binary.BigEndian.Uint16(raw[:2])
// TODO fix this
if typ&0b1000000000000000 == 0 {
eavp.Mandatory = true
}
// TODO: Check reserved bit
eavp.Type = AVPType(typ & 0b0011111111111111)
eavp.Length = binary.BigEndian.Uint16(raw[2:4])
val := raw[4:]
if eavp.Length != uint16(len(val)) {
return fmt.Errorf("PEAP-Extension: Invalid length: %d, should be %d", eavp.Length, len(val))
}
return nil
}
func (eavp ExtensionAVP) Encode() []byte {
buff := []byte{
0,