A transport-independent RADIUS packet and attribute toolkit for MoonBit.
moon add shangwuxi/moonradius@0.1.1import {
"shangwuxi/moonradius" @radius,
}moon run examples/minimalcode=Access-Request
identifier=42
wire_bytes=97
diagnostics=0let request = @radius.Packet::request(@radius.AccessRequest, 1)
.with_attribute(@radius.Attribute::text(@radius.User_Name, "alice"))
let wire = @radius.encode(request)
let parsed = @radius.decode(wire)
let diagnostics = @radius.diagnose(wire)moon fmt --check
moon check --deny-warn
moon build --target wasm-gc --deny-warn
moon test --target wasm-gc
moon run examples/minimalpub(open) trait DatagramTransport {
fn send(Self, Packet) -> Unit raise TransportError
fn receive(Self) -> Packet raise TransportError
}pub(all) suberror RadiusError {
TooShort
InvalidCode(Int)
InvalidLength(Int)
AttributeTruncated(Int)
AttributeTooShort(Int)
InvalidAuthenticator
Unsupported(String)
InvalidAttribute(String)
}pub struct AccessPolicy {
credentials : Array[Credential]
require_chap : Bool
challenge : Bytes
reply_message : String?
}pub struct AccountingRecord {
session_id : String?
status_type : Int?
input_octets : Int?
output_octets : Int?
input_packets : Int?
output_packets : Int?
}pub struct Attribute {
kind : Byte
value : Bytes
}pub struct Credential {
username : String
password : Bytes
}pub struct DictionaryEntry {
name : String
code : Byte
kind : String
}pub struct IPv4 {
first : Byte
second : Byte
third : Byte
fourth : Byte
}impl DatagramTransport for MemoryTransportfn Packet::with_response_authenticator(self : Packet, request_authenticator : Bytes, secret : Bytes) -> Packet raise RadiusErrorfn Packet::with_vendor_attribute(self : Packet, vendor : VendorAttribute) -> Packet raise RadiusErrorpub struct PacketStats {
attributes : Int
vendor_attributes : Int
total_value_bytes : Int
}pub struct RequestKey {
identifier : Byte
authenticator : Bytes
}pub struct ServerConfig {
secret : Bytes
access_policy : AccessPolicy
accounting_enabled : Bool
reject_malformed : Bool
}pub struct VendorAttribute {
vendor_id : Int
kind : Byte
value : Bytes
}fn access_response(request : Packet, decision : AccessDecision, secret : Bytes) -> Packet raise RadiusErrorfn chap_response(identifier : Byte, password : Bytes, challenge : Bytes) -> Bytesfn constant_time_equal(left : Bytes, right : Bytes) -> Boolfn decide_access(packet : Packet, policy : AccessPolicy, secret : Bytes) -> AccessDecision raise RadiusErrorfn decrypt_user_password(encrypted : Bytes, secret : Bytes, request_authenticator : Bytes) -> Bytes raise RadiusErrorfn encrypt_user_password(password : Bytes, secret : Bytes, request_authenticator : Bytes) -> Bytes raise RadiusErrorfn make_accounting_stop(identifier : Byte, authenticator : Bytes, session_id : String, input_octets : Int, output_octets : Int) -> Packetfn make_chap_password(identifier : Byte, password : Bytes, challenge : Bytes) -> Bytesfn response_authenticator(packet : Packet, request_authenticator : Bytes, secret : Bytes) -> Bytes raise RadiusErrorfn trim_zero_padding(value : Bytes) -> Bytesfn verify_response_authenticator(packet : Packet, request_authenticator : Bytes, secret : Bytes) -> Bool raise RadiusErrorInstall
Download zipA transport-independent RADIUS packet and attribute toolkit for MoonBit.