mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 06:04:21 +01:00
Create common package
Moves cryptographer to common. Also adds constants and defines the leghtn of the locator to avoid hardcoding it in almost every file
This commit is contained in:
0
common/__init__.py
Normal file
0
common/__init__.py
Normal file
8
common/constants.py
Normal file
8
common/constants.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# Locator
|
||||
LOCATOR_LEN_HEX = 32
|
||||
LOCATOR_LEN_BYTES = LOCATOR_LEN_HEX // 2
|
||||
|
||||
# HTTP
|
||||
HTTP_OK = 200
|
||||
HTTP_BAD_REQUEST = 400
|
||||
HTTP_SERVICE_UNAVAILABLE = 503
|
||||
@@ -8,17 +8,12 @@ from pisa.logger import Logger
|
||||
from pisa.inspector import Inspector
|
||||
from pisa.appointment import Appointment
|
||||
from pisa.block_processor import BlockProcessor
|
||||
from common.constants import HTTP_OK, HTTP_BAD_REQUEST, HTTP_SERVICE_UNAVAILABLE
|
||||
|
||||
|
||||
# ToDo: #5-add-async-to-api
|
||||
app = Flask(__name__)
|
||||
|
||||
HTTP_OK = 200
|
||||
HTTP_BAD_REQUEST = 400
|
||||
HTTP_SERVICE_UNAVAILABLE = 503
|
||||
|
||||
logger = Logger("API")
|
||||
|
||||
watcher = None
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||
from cryptography.exceptions import InvalidSignature
|
||||
|
||||
from common.constants import LOCATOR_LEN_HEX
|
||||
|
||||
from pisa import errors
|
||||
import pisa.conf as conf
|
||||
from pisa.logger import Logger
|
||||
@@ -64,7 +66,7 @@ class Inspector:
|
||||
rcode = errors.APPOINTMENT_WRONG_FIELD_TYPE
|
||||
message = "wrong locator data type ({})".format(type(locator))
|
||||
|
||||
elif len(locator) != 32:
|
||||
elif len(locator) != LOCATOR_LEN_HEX:
|
||||
rcode = errors.APPOINTMENT_WRONG_FIELD_SIZE
|
||||
message = "wrong locator size ({})".format(len(locator))
|
||||
# TODO: #12-check-txid-regexp
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import binascii
|
||||
|
||||
from pisa.cryptographer import Cryptographer
|
||||
from common.cryptographer import Cryptographer
|
||||
from pisa.encrypted_blob import EncryptedBlob
|
||||
from test.unit.conftest import get_random_value_hex
|
||||
|
||||
|
||||
Reference in New Issue
Block a user