#  All attribute lengths are implicit, and are calculated automatically
#
#  Input is of the form:
#
#	WORD ...
#
#  The WORD is a keyword which indicates the format of the following text.
#  WORD is one of:
#
#	raw - read the grammar defined below, and encode-pair an attribute.
#	      The grammar supports a trivial way of describing RADIUS
#	      attributes, without reference to dictionaries or fancy
#	      parsers
#
#	encode-pair - reads "Attribute-Name = value", encode-pairs it, and prints
#	         the result as text.
#		use "-" to encode-pair the output of the last command
#
#	decode-pair - reads hex, and decode-pairs it "Attribute-Name = value"
#		use "-" to decode-pair the output of the last command
#
#	data - the expected output of the previous command, in ASCII form.
#	       if the actual command output is different, an error message
#	       is produced, and the program terminates.
#
#
#  The "raw" input satisfies the following grammar:
#
#	Identifier = 1*DIGIT *( "." 1*DIGIT )
#
#	HEXCHAR = HEXDIG HEXDIG
#
#	STRING = DQUOTE *CHAR DQUOTE
#
#	TLV = "{" 1*DIGIT DATA "}"
#
#	DATA = 1*HEXCHAR / 1*TLV / STRING
#
#	LINE = Identifier DATA
#
#  The "Identifier" is a RADIUS attribute identifier, as given in the draft.
#
#	e.g.	1		for User-Name
#		26.9.1		Vendor-Specific, Cisco, Cisco-AVPAir
#		241.1		Extended Attribute, number 1
#		241.2.3		Extended Attribute 2, data type TLV, TLV type 3
#		etc.
#
#  The "DATA" portion is the contents of the RADIUS Attribute.
#
#		123456789abcdef hex string
#		12 34 56 ab	with spaces for clarity
#		"hello"	 	Text string
#		{ 1 abcdef }	TLV, TLV-Type 1, data "abcdef"
#
#  TLVs can be nested:
#
#	{ tlv-type { tlv-type data } }		{ 3 { 4 01020304 } }
#
#  TLVs can be concatencated
#
#	{tlv-type data } { tlv-type data}	{ 3 040506 } { 8 aabbcc }
#
#  The "raw" data is encode-paird without reference to dictionaries.  Any
#  valid string is parsed to a RADIUS attribute.  The resulting RADIUS
#  attribute *may not* be correctly formatted to the relevant RADIUS
#  specifications.  i.e. you can use this tool to create attribute 1
#  (User-Name), which is encode-paird as a series of TLVs.  That's up to you.
#
#  The purpose of the "raw" command is to have a simple way of encoding
#  attributes which is independent of any dictionaries or packet processing
#  routines.
#
#  The output data is the hex version of the encode-paird attribute.
#

proto radius
proto-dictionary radius
fuzzer-out radius

encode-pair User-Name = "bob"
match 01 05 62 6f 62

decode-pair -
match User-Name = "bob"

decode-pair 01 05 62 6f 62
match User-Name = "bob"

#
#  The Type/Length is OK, but the attribute data is of the wrong size.
#
decode-pair 04 04 ab cd
match raw.NAS-IP-Address = 0xabcd

#  Zero-length attributes
decode-pair 01 02
match

# don't encode-pair zero-length attributes
# They are silently skipped
encode-pair User-Name = ""
match 

# except for CUI.  Thank you, WiMAX!
decode-pair 59 02
match Chargeable-User-Identity = 0x

# Hah! Thought you had it figured out, didn't you?
encode-pair -
match 59 02

pair Framed-IP-Address = 127.0.0.1/32
match Framed-IP-Address = 127.0.0.1

pair Framed-IP-Address = 127.0.0.1/323
match Invalid IPv4 mask length "/323".  Should be between 0-32

pair Framed-IP-Address = 127.0.0.1/30
match Invalid IPv4 mask length "/30".  Only "/32" permitted for non-prefix types

pair Framed-IP-Address = *
match Framed-IP-Address = 0.0.0.0

pair Framed-IP-Address = 127
match Framed-IP-Address = 0.0.0.127

pair Framed-IP-Address = 127.0
match Framed-IP-Address = 127.0.0.0

#
#  The encode-pairr should work...
#
encode-pair -
match 08 06 7f 00 00 00

decode-pair -
match Framed-IP-Address = 127.0.0.0

pair Framed-IPv6-Prefix = ::1
match Framed-IPv6-Prefix = ::1/128

pair Framed-IPv6-Prefix = ::1/200
match Invalid IPv6 mask length "/200".  Should be between 0-128

pair Framed-IPv6-Prefix = ::1/200
match Invalid IPv6 mask length "/200".  Should be between 0-128

pair Framed-IPv6-Prefix = 11:22:33:44:55:66:77:88/128
match Framed-IPv6-Prefix = 11:22:33:44:55:66:77:88/128

pair Framed-IPv6-Prefix = *
match Framed-IPv6-Prefix = ::/128

pair PMIP6-Home-IPv4-HoA = 127/8
match PMIP6-Home-IPv4-HoA = 127.0.0.0/8

pair PMIP6-Home-IPv4-HoA = 127/8
match PMIP6-Home-IPv4-HoA = 127.0.0.0/8

#
#  Octets outside of the mask are OK, but
#  are mashed to zero.
#
pair PMIP6-Home-IPv4-HoA = 127.63/8
match PMIP6-Home-IPv4-HoA = 127.0.0.0/8

#
#  Unless you give a good mask.
#
pair PMIP6-Home-IPv4-HoA = 127.63/16
match PMIP6-Home-IPv4-HoA = 127.63.0.0/16

pair PMIP6-Home-IPv4-HoA = 127.999/16
match Failed to parse IPv4 prefix string "127.999/16"

pair PMIP6-Home-IPv4-HoA = 127.bob/16
match Failed to parse IPv4 prefix string "127.bob/16"

pair PMIP6-Home-IPv4-HoA = 127.63/15
match PMIP6-Home-IPv4-HoA = 127.62.0.0/15

pair PMIP6-Home-IPv4-HoA = 127.63.1/24
match PMIP6-Home-IPv4-HoA = 127.63.1.0/24

pair PMIP6-Home-IPv4-HoA = 127.63.1.6
match PMIP6-Home-IPv4-HoA = 127.63.1.6/32

pair PMIP6-Home-IPv4-HoA = 256/8
match Failed to parse IPv4 prefix string "256/8"

pair PMIP6-Home-IPv4-HoA = bob/8
match Failed to parse IPv4 prefix string "bob/8"

#
#  Concatenated messages
#
pair EAP-Message = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa"
match EAP-Message = 0x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787861

encode-pair -
match 4f ff 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 4f 32 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 61

decode-pair -
match EAP-Message = 0x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787861

count
match 73
