Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 2d74c04

Browse files
authored
Merge pull request #77 from jinnerbichler/seed_check
Issue #45: Seed check
2 parents e517afd + a91a4d1 commit 2d74c04

File tree

6 files changed

+254
-184
lines changed

6 files changed

+254
-184
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ docs/_build/
2121
# Note: For environment- or IDE-specific metadata (e.g., .DS_Store, .idea, etc.
2222
# you can add these to your own "global" .gitignore file.
2323
# https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
24-
#
24+
#

iota/crypto/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@
2020
Fragments are used to divide up really long tryte sequences into
2121
manageable chunks (similar in concept to AES blocks).
2222
"""
23+
24+
25+
class SeedWarning(Warning):
26+
"""
27+
Warning for inappropriate seeds.
28+
"""
29+
pass

iota/crypto/types.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from __future__ import absolute_import, division, print_function, \
33
unicode_literals
44

5+
import warnings
56
from typing import MutableSequence, Optional, Tuple
67

7-
from iota.crypto import FRAGMENT_LENGTH, HASH_LENGTH
8+
from iota.crypto import FRAGMENT_LENGTH, HASH_LENGTH, SeedWarning
89
from iota.crypto.kerl import Kerl
910
from iota.exceptions import with_context
1011
from iota.transaction.base import Bundle
@@ -73,9 +74,22 @@ class Seed(TryteString):
7374
7475
IMPORTANT: For maximum security, a seed must be EXACTLY 81 trytes!
7576
77+
WARNINGS:
78+
.. warning:: :py:class:`SeedWarning` if seed has inappropriate length.
79+
7680
References:
7781
- https://forum.iota.org/t/why-arent-seeds-longer-than-81-trytes-more-secure/1278
7882
"""
83+
84+
def __init__(self, trytes=None):
85+
# type: (Optional[TrytesCompatible]) -> None
86+
if trytes and len(trytes) > Hash.LEN:
87+
warnings.warn("Seed has inappropriate length! "
88+
"(https://forum.iota.org/t/why-arent-seeds-longer-than-81-trytes-more-secure/1278)",
89+
category=SeedWarning)
90+
91+
super(Seed, self).__init__(trytes)
92+
7993
@classmethod
8094
def random(cls, length=Hash.LEN):
8195
"""

iota/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
# Custom types for type hints and docstrings.
34-
TrytesCompatible = Union[AnyStr, bytearray, 'TryteString']
34+
TrytesCompatible = Union[AnyStr, bytearray, 'TryteString']
3535

3636

3737
def trits_from_int(n, pad=None):

0 commit comments

Comments
 (0)