wyzeapy.crypto

 1#  Copyright (c) 2021. Mulliken, LLC - All Rights Reserved
 2#  You may use, distribute and modify this code under the terms
 3#  of the attached license. You should have received a copy of
 4#  the license with this file. If not, please write to:
 5#  katie@mulliken.net to receive a copy
 6import hashlib
 7import hmac
 8import urllib.parse
 9from typing import Dict, Union, Any
10
11from .const import FORD_APP_SECRET, OLIVE_SIGNING_SECRET
12
13
14def olive_create_signature(payload: Union[Dict[Any, Any], str], access_token: str) -> str:
15    if isinstance(payload, dict):
16        body = ""
17        for item in sorted(payload):
18            body += item + "=" + str(payload[item]) + "&"
19
20        body = body[:-1]
21
22    else:
23        body = payload
24
25    access_key = "{}{}".format(access_token, OLIVE_SIGNING_SECRET)
26
27    secret = hashlib.md5(access_key.encode()).hexdigest()
28    return hmac.new(secret.encode(), body.encode(), hashlib.md5).hexdigest()
29
30
31def ford_create_signature(url_path: str, request_method: str, payload: Dict[Any, Any]) -> str:
32    string_buf = request_method + url_path
33    for entry in sorted(payload.keys()):
34        string_buf += entry + "=" + payload[entry] + "&"
35
36    string_buf = string_buf[:-1]
37    string_buf += FORD_APP_SECRET
38    urlencoded = urllib.parse.quote_plus(string_buf)
39    return hashlib.md5(urlencoded.encode()).hexdigest()
def olive_create_signature(payload: Union[Dict[Any, Any], str], access_token: str) -> str:
15def olive_create_signature(payload: Union[Dict[Any, Any], str], access_token: str) -> str:
16    if isinstance(payload, dict):
17        body = ""
18        for item in sorted(payload):
19            body += item + "=" + str(payload[item]) + "&"
20
21        body = body[:-1]
22
23    else:
24        body = payload
25
26    access_key = "{}{}".format(access_token, OLIVE_SIGNING_SECRET)
27
28    secret = hashlib.md5(access_key.encode()).hexdigest()
29    return hmac.new(secret.encode(), body.encode(), hashlib.md5).hexdigest()
def ford_create_signature(url_path: str, request_method: str, payload: Dict[Any, Any]) -> str:
32def ford_create_signature(url_path: str, request_method: str, payload: Dict[Any, Any]) -> str:
33    string_buf = request_method + url_path
34    for entry in sorted(payload.keys()):
35        string_buf += entry + "=" + payload[entry] + "&"
36
37    string_buf = string_buf[:-1]
38    string_buf += FORD_APP_SECRET
39    urlencoded = urllib.parse.quote_plus(string_buf)
40    return hashlib.md5(urlencoded.encode()).hexdigest()