Custom stations: Revisit checksum generation
Some AVRs do not allow an ID larger than 15 characters. Thanks to Marc for pointing that out. Use a MD5 hash (128), XOR fold it (64) and cut it to size (48). This way we _should_ still have enough uniqueness and can generate a checksum which fits the limits.
This commit is contained in:
parent
19e0ff8649
commit
c6f4fe1691
1 changed files with 8 additions and 3 deletions
|
@ -75,7 +75,12 @@ def get_stations_by_category(category):
|
||||||
return stations
|
return stations
|
||||||
|
|
||||||
|
|
||||||
def get_checksum(feed):
|
def get_checksum(feed, charlimit=12):
|
||||||
hash_feed = feed.encode()
|
hash_feed = feed.encode()
|
||||||
hash_object = hashlib.sha256(hash_feed)
|
hash_object = hashlib.md5(hash_feed)
|
||||||
return hash_object.hexdigest()
|
digest = hash_object.digest()
|
||||||
|
xor_fold = bytearray(digest[:8])
|
||||||
|
for i, b in enumerate(digest[8:]):
|
||||||
|
xor_fold[i] ^= b
|
||||||
|
digest_xor_fold = ''.join(format(x, '02x') for x in bytes(xor_fold))
|
||||||
|
return digest_xor_fold[:charlimit]
|
||||||
|
|
Loading…
Reference in a new issue