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:
Sergi Delgado Segura
2019-12-05 11:02:17 +01:00
parent f0150ce585
commit babb746dbd
6 changed files with 13 additions and 8 deletions

0
common/__init__.py Normal file
View File

8
common/constants.py Normal file
View 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

View File

@@ -8,17 +8,12 @@ from pisa.logger import Logger
from pisa.inspector import Inspector from pisa.inspector import Inspector
from pisa.appointment import Appointment from pisa.appointment import Appointment
from pisa.block_processor import BlockProcessor from pisa.block_processor import BlockProcessor
from common.constants import HTTP_OK, HTTP_BAD_REQUEST, HTTP_SERVICE_UNAVAILABLE
# ToDo: #5-add-async-to-api # ToDo: #5-add-async-to-api
app = Flask(__name__) app = Flask(__name__)
HTTP_OK = 200
HTTP_BAD_REQUEST = 400
HTTP_SERVICE_UNAVAILABLE = 503
logger = Logger("API") logger = Logger("API")
watcher = None watcher = None

View File

@@ -8,6 +8,8 @@ from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import load_pem_public_key from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.exceptions import InvalidSignature from cryptography.exceptions import InvalidSignature
from common.constants import LOCATOR_LEN_HEX
from pisa import errors from pisa import errors
import pisa.conf as conf import pisa.conf as conf
from pisa.logger import Logger from pisa.logger import Logger
@@ -64,7 +66,7 @@ class Inspector:
rcode = errors.APPOINTMENT_WRONG_FIELD_TYPE rcode = errors.APPOINTMENT_WRONG_FIELD_TYPE
message = "wrong locator data type ({})".format(type(locator)) message = "wrong locator data type ({})".format(type(locator))
elif len(locator) != 32: elif len(locator) != LOCATOR_LEN_HEX:
rcode = errors.APPOINTMENT_WRONG_FIELD_SIZE rcode = errors.APPOINTMENT_WRONG_FIELD_SIZE
message = "wrong locator size ({})".format(len(locator)) message = "wrong locator size ({})".format(len(locator))
# TODO: #12-check-txid-regexp # TODO: #12-check-txid-regexp

View File

@@ -1,6 +1,6 @@
import binascii import binascii
from pisa.cryptographer import Cryptographer from common.cryptographer import Cryptographer
from pisa.encrypted_blob import EncryptedBlob from pisa.encrypted_blob import EncryptedBlob
from test.unit.conftest import get_random_value_hex from test.unit.conftest import get_random_value_hex