diff --git a/src/interface.ts b/src/interface.ts index c22230f..160b593 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -1,14 +1,19 @@ import * as radius from 'radius'; import * as gblConfig from '../config'; import { IPacket } from './types/PacketHandler'; -import {Authentication} from "./auth"; -import {UDPServer} from "./server/UDPServer"; -import {RadiusService} from "./radius/RadiusService"; - -export type PacketDecoder = (msg: Buffer) => { - packet?: radius.RadiusPacket & IPacket; - secret: string; -}; +import { Authentication } from './auth'; +import { UDPServer } from './server/UDPServer'; +import { RadiusService } from './radius/RadiusService'; + +export type PacketDecoder = (msg: Buffer) => + | { + packet?: radius.RadiusPacket & IPacket; + secret: string; + } + | Promise<{ + packet?: radius.RadiusPacket & IPacket; + secret: string; + }>; export default class PackageInterface { private static _instance?: PackageInterface; diff --git a/src/radius/RadiusService.ts b/src/radius/RadiusService.ts index 9ddfaf3..70a57d4 100644 --- a/src/radius/RadiusService.ts +++ b/src/radius/RadiusService.ts @@ -27,7 +27,7 @@ export class RadiusService { msg: Buffer ): Promise<{ data: Buffer; expectAcknowledgment?: boolean } | undefined> { const { packet, secret } = packageInterface.packetDecoder - ? packageInterface.packetDecoder(msg) + ? await packageInterface.packetDecoder(msg) : this.defaultDecoder(msg); if (!packet) {