Skip to content

Commit fea5822

Browse files
author
auxten
committed
Fix unnecessary ord
1 parent 163c422 commit fea5822

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pycovenantsql/e2ee.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import hashlib
44
from binascii import hexlify, unhexlify
55

6-
76
BLOCK_SIZE = AES.block_size # Bytes
87

98
salt = unhexlify("3fb8877d37fdc04e4a4765EFb8ab7d36")
@@ -19,25 +18,31 @@ class PaddingError(Exception):
1918
def __init__(self, message):
2019
self.message = message
2120

21+
2222
pad = lambda s: s + ((BLOCK_SIZE - len(s) % BLOCK_SIZE) *
23-
chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)).encode('utf-8')
23+
chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)).encode('ascii')
24+
2425

2526
def unpad(s):
2627
in_len = len(s)
2728
if in_len == 0:
2829
raise PaddingError("empty input")
2930
pad_char = s[-1]
30-
pad_len = ord(s[in_len-1:])
31-
if pad_len > BLOCK_SIZE:
31+
if pad_char > BLOCK_SIZE:
3232
raise PaddingError("padding length > 16")
33-
for i in s[in_len-pad_len:]:
33+
for i in s[in_len - pad_char:]:
3434
if i != pad_char:
3535
raise PaddingError("unexpected padding char")
36-
return s[:-pad_len]
36+
return s[:-pad_char]
3737

3838

3939
# kdf does 2 times sha256 and takes the first 16 bytes
4040
def kdf(raw_key):
41+
"""
42+
kdf does 2 times sha256 and takes the first 16 bytes
43+
:param raw_key:
44+
:return:
45+
"""
4146
return hashlib.sha256(hashlib.sha256(raw_key + salt).digest()).digest()[:16]
4247

4348

0 commit comments

Comments
 (0)