Skip to content

Commit

Permalink
Fix encoding/decoding of signatures.
Browse files Browse the repository at this point in the history
How I wished we had unit tests...
  • Loading branch information
Luc Ducazu committed May 20, 2022
1 parent a4dd2c2 commit 76b497c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions irdata/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"""

import base64
import hashlib
import re
from hashlib import sha1

strip_regexp = re.compile("[^A-Z0-9]")

Expand Down Expand Up @@ -76,7 +76,9 @@ def make_signature(sequence, legacy=0):

if legacy:
sequence = normalise_sequence(sequence)
return base64.b64encode(sha1(sequence).digest())[:-1]
digest = hashlib.sha1(sequence.encode("utf-8")).digest()
b64enc = base64.b64encode(digest)[:-1]
return b64enc.decode("utf-8")


def process_file(f, out, column, separator=",", append=0, append_length=0, legacy=0):
Expand All @@ -99,7 +101,7 @@ def process_file(f, out, column, separator=",", append=0, append_length=0, legac
true value. This is not recommended.
"""

for line in f.xreadlines():
for line in f.readlines():
columns = line.rstrip("\n").split("\t")
inputs = columns[column].split(separator)
signatures = fix_signatures(inputs)
Expand Down

0 comments on commit 76b497c

Please sign in to comment.