(self)
| 495 | |
| 496 | class CryptoPassphraseGenerator(PasswordGenerator): |
| 497 | def __init__(self): |
| 498 | self._vocabulary = None # type: Optional[List[str]] |
| 499 | dice_path = os.path.join(os.path.dirname(__file__), 'resources', 'bip-39.english.txt') |
| 500 | if os.path.isfile(dice_path): |
| 501 | with open(dice_path, 'r', encoding='utf-8') as dw: |
| 502 | self._vocabulary = [] |
| 503 | for line in dw.readlines(): |
| 504 | if not line: |
| 505 | continue |
| 506 | if line.startswith('--'): |
| 507 | continue |
| 508 | words = [x.strip() for x in line.split()] |
| 509 | word = words[1] if len(words) >= 2 else words[0] |
| 510 | self._vocabulary.append(word) |
| 511 | |
| 512 | unique_words = set((x.lower() for x in self._vocabulary)) |
| 513 | if len(self._vocabulary) != len(unique_words): |
| 514 | raise Exception(f'Word list file \"{dice_path}\" contains non-unique words.') |
| 515 | if len(unique_words) != 2 ** 11: |
| 516 | raise Exception(f'Word list file \"{dice_path}\" is incorrect crypto dictionary.') |
| 517 | else: |
| 518 | raise Exception(f'Word list file \"{dice_path}\" not found.') |
| 519 | |
| 520 | def get_vocabulary(self): # type: () -> Iterator[str] |
| 521 | return (x for x in self._vocabulary) |
nothing calls this directly
no outgoing calls
no test coverage detected