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

10 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

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

2from dataclasses import dataclass 

3from secrets import token_hex 

4 

5 

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

7class TokenIdentifier: 

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

9 

10 hex_string: str 

11 

12 @classmethod 

13 def generate(cls): 

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

15 return TokenIdentifier(hex_string=token_hex(40)) 

16 

17 def __str__(self): 

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

19 return self.hex_string