Documentation
¶
Overview ¶
Package dictionary maps RADIUS attribute type numbers to human-readable metadata: the attribute name, the wire encoding of its Value (string, integer, IP address, raw octets, vendor-specific, or RFC 6929 extended), whether the value is encrypted on the wire, and whether it carries an RFC 2868 tag.
A single global Dictionary is initialized at package load time with the standard attributes defined by RFC 2865 and RFC 2866. Callers may register additional attributes (vendor-specific, site-specific, or future RFCs) into the default dictionary, or construct isolated Dictionary instances with New() for testing or for parallel use of conflicting schemas.
The dictionary performs no encoding or decoding of attribute values itself; it only describes them so that callers can dispatch to the correct codec.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(def AttributeDef) error
Register adds def to the default dictionary. See Dictionary.Register for semantics.
func ResetForTest ¶
func ResetForTest()
ResetForTest clears all entries from the default dictionary. As the name implies this is intended for use in tests that need to assert behavior with an empty or re-seeded dictionary; production code should not call it.
Types ¶
type AttributeDef ¶
type AttributeDef struct {
// Type is the 1-byte attribute type number (1..255).
Type byte
// Name is the canonical attribute name with hyphens, e.g. "User-Name".
Name string
// ValueType selects the wire encoding of the Value field.
ValueType ValueType
// Encrypt is 0 for cleartext attributes and 1 for User-Password-style
// attributes whose Value is hidden using the RFC 2865 §5.2 algorithm.
// Other values are reserved for future RFCs.
Encrypt int
// HasTag is true for RFC 2868 tagged attributes. Tagged attribute
// encoding/decoding is handled by the crypto package (EncodeTunnelTag /
// DecodeTunnelTag).
HasTag bool
}
AttributeDef describes a single attribute's wire format. A Dictionary maps Type numbers and Names to AttributeDef pointers.
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
Dictionary maps attribute Type numbers and Names to AttributeDef entries. All methods are safe for concurrent use.
func Default ¶
func Default() *Dictionary
Default returns the shared dictionary that init() has populated with the standard RFC 2865 and RFC 2866 attributes. Callers may Register additional attributes into it; for test isolation, use ResetForTest followed by re-registration, or construct a fresh Dictionary via New().
func New ¶
func New() *Dictionary
New returns an empty Dictionary. The caller owns the returned instance and may Register into it without affecting the global default dictionary.
func (*Dictionary) Lookup ¶
func (d *Dictionary) Lookup(t byte) (*AttributeDef, bool)
Lookup returns the AttributeDef for the given Type and true, or false if no attribute with that Type has been registered.
func (*Dictionary) LookupName ¶
func (d *Dictionary) LookupName(name string) (*AttributeDef, bool)
LookupName returns the AttributeDef for the given Name and true, or false if no attribute with that Name has been registered.
func (*Dictionary) Register ¶
func (d *Dictionary) Register(def AttributeDef) error
Register stores def in the dictionary, indexed by both Type and Name. A subsequent Register with the same Type overwrites the prior entry and updates the Name index accordingly. Returns ErrInvalidAttribute if Name is empty.
func (*Dictionary) Size ¶
func (d *Dictionary) Size() int
Size returns the number of attribute definitions currently registered.
type ValueType ¶
type ValueType int
ValueType describes how an attribute's Value field is encoded on the wire.
const ( // TypeString is a UTF-8 octet string (RFC 2865 §5). TypeString ValueType = iota // TypeInteger is a 4-byte big-endian unsigned integer. TypeInteger // TypeIPAddr is a 4-byte IPv4 address. TypeIPAddr // TypeIPv6Addr is a 16-byte IPv6 address (RFC 3162). TypeIPv6Addr // TypeOctets is a raw octet string with no implied interpretation. TypeOctets // TypeVSA marks a Vendor-Specific attribute (Type 26) whose Value begins // with a 4-byte Vendor-Id followed by vendor-defined data. TypeVSA // TypeExtended marks an RFC 6929 extended attribute. TypeExtended )