Skip to content
This repository was archived by the owner on Apr 19, 2024. It is now read-only.

Commit fd4f150

Browse files
committed
trivial versions of Func and Multihash classes
1 parent 91ada6d commit fd4f150

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

multihash.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@
33
# Initial author: Ivan Vilata-i-Balaguer
44
# License: MIT
55

6+
from collections import namedtuple
7+
from enum import Enum
8+
9+
10+
class Func(Enum):
11+
"""An enumeration of hash functions supported by multihash.
12+
13+
The value of each member corresponds to its integer code.
14+
15+
>>> Func.sha1.value == 0x11
16+
True
17+
"""
18+
sha1 = 0x11
19+
sha2_256 = 0x12
20+
sha2_512 = 0x13
21+
sha3 = 0x14
22+
blake2b = 0x40
23+
blake2s = 0x41
24+
25+
26+
class Multihash(namedtuple('Multihash', 'func length digest')):
27+
"""A named tuple representing multihash function, length and digest.
28+
29+
>>> mh = Multihash(Func.sha1, 20, b'BINARY_DIGEST')
30+
>>> mh == (Func.sha1, 20, b'BINARY_DIGEST')
31+
True
32+
>>> mh == (mh.func, mh.length, mh.digest)
33+
True
34+
"""
35+
__slots__ = ()
36+
37+
638
def _test():
739
import doctest
840
doctest.testmod()

0 commit comments

Comments
 (0)