content_hash.encodes.swarm.encode()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 13
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
"""Encode module for Swarm."""
2
3
from multiformats import CID, multihash
4
from content_hash.utils import raw_cid_value
5
6
def encode(value):
7
    """
8
    Encode Swarm.
9
10
    :param bytes value: a decoded content
11
12
    :return: the encoded content
13
    :rtype: bytes
14
    """
15
16
    mhash = multihash.wrap(bytes.fromhex(value), 'keccak-256')
17
    cid = CID(base='base58btc', codec='swarm-manifest', version=1, digest=mhash)
18
    return raw_cid_value(cid)
19