#
#  time deltas, which don't require setting TZ=UTC
#
proto radius
proto-dictionary radius
load-dictionary dictionary.test
fuzzer-out radius

#
#  Time delta in milliseconds.
#
pair Unit-TLV.Delta-MSec = 5
match Unit-TLV = { Delta-MSec = 5 }

encode-pair -
match fe 08 02 06 00 00 00 05

decode-pair -
match Unit-TLV = { Delta-MSec = 5 }

pair Unit-TLV.Delta-Sec = 10
match Unit-TLV = { Delta-Sec = 10 }

encode-pair -
match fe 08 03 06 00 00 00 0a

decode-pair -
match Unit-TLV = { Delta-Sec = 10 }

#
#  Allow encoding as nested VPs
#
encode-pair Unit-TLV.Milliseconds = 1
match fe 08 01 06 00 00 00 01

encode-pair Unit-TLV = { Milliseconds = 1 }
match fe 08 01 06 00 00 00 01

#
#  Various data types and time resolutions
#
encode-pair Unit-TLV.Delta-MSec-uint16 = 65ms
match fe 06 04 04 00 41

# The attribute is milliseconds, so we print it as
# milliseconds by default.
decode-pair -
match Unit-TLV = { Delta-MSec-uint16 = 65 }

encode-pair Unit-TLV.Delta-MSec-int32 = -32768
match fe 08 0a 06 ff ff 80 00

decode-pair -
match Unit-TLV = { Delta-MSec-int32 = -32768 }

pair Unit-TLV.Delta-MSec-int32 = -32768
match Unit-TLV = { Delta-MSec-int32 = -32768 }

encode-pair Unit-TLV.Delta-MSec-int16 = -32768
match fe 06 06 04 80 00

decode-pair -
match Unit-TLV = { Delta-MSec-int16 = -32768 }

pair Unit-TLV.Delta-MSec-int16 = -32768
match Unit-TLV = { Delta-MSec-int16 = -32768 }

# Regression test for broken signed promotion
encode-pair Unit-TLV.Delta-MSec-int32 = -32768
match fe 08 0a 06 ff ff 80 00

decode-pair -
match Unit-TLV = { Delta-MSec-int32 = -32768 }

pair Unit-TLV.Delta-MSec-int32 = -32768
match Unit-TLV = { Delta-MSec-int32 = -32768 }

#
#	Min/Max values & overflows
#

# Internal format is int64_t
pair Unit-TLV.Delta-MSec-uint16 = 9223372036853
match Unit-TLV = { Delta-MSec-uint16 = 9223372036853 }

pair Unit-TLV.Delta-MSec-uint32 = 9223372036853
match Unit-TLV = { Delta-MSec-uint32 = 9223372036853 }

# therefore, the encode should limit to the data type.
encode-pair Unit-TLV.Delta-MSec-uint16 = 9223372036853
match fe 06 04 04 ff ff

encode-pair Unit-TLV.Delta-MSec-uint32 = 9223372036853
match fe 08 08 06 ff ff ff ff

# lets see encode/decode based on the data type for unsigned
encode-pair Unit-TLV.Delta-MSec-uint16 = 65535
match fe 06 04 04 ff ff

decode-pair -
match Unit-TLV = { Delta-MSec-uint16 = 65535 }

encode-pair Unit-TLV.Delta-MSec-uint32 = 4294967295
match fe 08 08 06 ff ff ff ff

decode-pair -
match Unit-TLV = { Delta-MSec-uint32 = 4294967295 }

# ... and signed
encode-pair Unit-TLV.Delta-MSec-int16 = 32767
match fe 06 06 04 7f ff

decode-pair -
match Unit-TLV = { Delta-MSec-int16 = 32767 }

encode-pair Unit-TLV.Delta-MSec-int32 = 2147483647
match fe 08 0a 06 7f ff ff ff

decode-pair -
match Unit-TLV = { Delta-MSec-int32 = 2147483647 }

count
match 66
