[Security-sig] Unified TLS API for Python: Round 2

Ethan Furman ethan at stoneleaf.us
Mon Jan 23 21:16:01 EST 2017


On 01/23/2017 05:59 PM, Nathaniel Smith wrote:
> On Sun, Jan 22, 2017 at 4:01 AM, Cory Benfield wrote:
>> On 20 Jan 2017, at 23:00, Nathaniel Smith wrote:

>>> - given that for next protocol negotiation we have to accept arbitrary
>>> bytestrings and the primary value of the NextProtocol class is to
>>> protect against typos, I wonder if it would simplify things slightly
>>> to make the attributes of this class just *be* bytestrings. I.e. what
>>> you have now but without the inheritance from enum.
>>
>> While we *could*, I don’t think the value-add of doing this is very high.
>>  Basically the only thing it simplifies is the type declaration, and I
>>  don’t know that it’s worth doing that. ;)
>
> Well, and the code that receives the values, which currently has to
> handle both enums and bytestrings. Agreed it's not a big deal, it just
> seems like the value the enum is adding is all negative.

Enum can be mixed with other types:

--- 8< ----------------------------------------
from enum import Enum

class NextProtocol(bytes, Enum):
     H2 = b'h2'
     H2C = b'h2c'
     HTTP1 = b'http/1.1'
     WEBRTC = b'webrtc'
     C_WEBRTC = b'c-webrtc'
     FTP = b'ftp'
     STUN = b'stun.nat-discovery'
     TURN = b'stun.turn'

print(NextProtocol.STUN)
# NextProtocol.STUN

print(isinstance(NextProtocol.STUN, bytes))
# True

--- 8< ----------------------------------------

--
~Ethan~


More information about the Security-SIG mailing list