pyradius / pyrad

Python RADIUS Implementation
BSD 3-Clause "New" or "Revised" License
294 stars 186 forks source link

Allow octets type to accept string and integer values for parsing #155

Closed nward closed 3 years ago

nward commented 3 years ago

The juniper/ERX dictionary from the FreeRADIUS project includes using octets attributes with values, which are written in the dictionary as integers, i.e.:

ATTRIBUTE   ERX-Acct-Request-Reason         210 octets
VALUE   ERX-Acct-Request-Reason     Acct-Start-Ack      1
VALUE   ERX-Acct-Request-Reason     Periodic        2
VALUE   ERX-Acct-Request-Reason     IP-Active       4
...etc...

pyrad doesn't parse this at present, and errors out as "1" in python is not of bytes type.

This PR adds this functionality, by allowing either str or bytes starting with 0x, and checking for digits-only values, and packing them as an integer to get a bytes output the same as if the 0x integer value had been passed.

Additionally, in the EncodeOctets function (and many Encode* function in tools.py) the parameter is called str, which conflicts with the python basic string type. In the EncodeOctets function I have renamed this to octetstring.

nward commented 3 years ago

I've subsequently added a fix for #152, and tests for it. Thanks!

nerosketch commented 3 years ago

I need these changes too. I also have "juniper", and I have similar error.

nward commented 3 years ago

Thanks @nerosketch - I have no idea why I used type() rather than isinstance.. brain fart perhaps!

Istvan91 commented 3 years ago

looks good to me - I'll try to push a new version this weekend.