mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 21:43:21 +00:00
zerver/lib/mobile_auth_otp: Sweep force_str.
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
# have it here as part of testing the overall library.
|
# have it here as part of testing the overall library.
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
from zerver.lib.str_utils import force_str
|
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
|
|
||||||
def xor_hex_strings(bytes_a: str, bytes_b: str) -> str:
|
def xor_hex_strings(bytes_a: str, bytes_b: str) -> str:
|
||||||
@@ -25,11 +24,11 @@ def ascii_to_hex(input_string: str) -> str:
|
|||||||
|
|
||||||
def hex_to_ascii(input_string: str) -> str:
|
def hex_to_ascii(input_string: str) -> str:
|
||||||
"""Given a hex array, decode it back to a string"""
|
"""Given a hex array, decode it back to a string"""
|
||||||
return force_str(binascii.unhexlify(input_string))
|
return binascii.unhexlify(input_string).decode('utf8')
|
||||||
|
|
||||||
def otp_encrypt_api_key(user_profile: UserProfile, otp: str) -> str:
|
def otp_encrypt_api_key(user_profile: UserProfile, otp: str) -> str:
|
||||||
assert len(otp) == UserProfile.API_KEY_LENGTH * 2
|
assert len(otp) == UserProfile.API_KEY_LENGTH * 2
|
||||||
hex_encoded_api_key = ascii_to_hex(force_str(user_profile.api_key))
|
hex_encoded_api_key = ascii_to_hex(user_profile.api_key)
|
||||||
assert len(hex_encoded_api_key) == UserProfile.API_KEY_LENGTH * 2
|
assert len(hex_encoded_api_key) == UserProfile.API_KEY_LENGTH * 2
|
||||||
return xor_hex_strings(hex_encoded_api_key, otp)
|
return xor_hex_strings(hex_encoded_api_key, otp)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user