Coverage for src/kwai/modules/identity/tokens/token_identifier.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that defines a value object for a token identifier.""" 

2 

3from dataclasses import dataclass 

4from secrets import token_hex 

5 

6 

7@dataclass(frozen=True, kw_only=True) 

8class TokenIdentifier: 

9 """A value object for a token identifier.""" 

10 

11 hex_string: str 

12 

13 @classmethod 

14 def generate(cls): 

15 """Create a new token identifier with a random text string.""" 

16 return TokenIdentifier(hex_string=token_hex(40)) 

17 

18 def __str__(self): 

19 """Return a string representation of the token.""" 

20 return self.hex_string