Agregar funciones para encriptar
This commit is contained in:
parent
c9f9ea526f
commit
5cdbb0aaa7
|
@ -23,7 +23,6 @@ import hashlib
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import locale
|
import locale
|
||||||
import math
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -3766,6 +3765,4 @@ def parse_xml2(xml_str):
|
||||||
return etree.fromstring(xml_str.encode('utf-8'))
|
return etree.fromstring(xml_str.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def round_up(value):
|
|
||||||
return int(math.ceil(value))
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# ~ Empresa Libre
|
||||||
|
# ~ Copyright (C) 2016-2019 Mauricio Baeza Servin (public@elmau.net)
|
||||||
|
# ~
|
||||||
|
# ~ This program is free software: you can redistribute it and/or modify
|
||||||
|
# ~ it under the terms of the GNU General Public License as published by
|
||||||
|
# ~ the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# ~ (at your option) any later version.
|
||||||
|
# ~
|
||||||
|
# ~ This program is distributed in the hope that it will be useful,
|
||||||
|
# ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# ~ GNU General Public License for more details.
|
||||||
|
# ~
|
||||||
|
# ~ You should have received a copy of the GNU General Public License
|
||||||
|
# ~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
|
from cryptography.fernet import Fernet
|
||||||
|
from cryptography.hazmat.backends import default_backend
|
||||||
|
from cryptography.hazmat.primitives import hashes
|
||||||
|
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||||
|
|
||||||
|
|
||||||
|
def round_up(value):
|
||||||
|
return int(math.ceil(value))
|
||||||
|
|
||||||
|
|
||||||
|
def _get_key(password):
|
||||||
|
salt = os.urandom(16)
|
||||||
|
kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt,
|
||||||
|
iterations=100000, backend=default_backend())
|
||||||
|
key = base64.urlsafe_b64encode(kdf.derive(password.encode()))
|
||||||
|
return key
|
||||||
|
|
||||||
|
|
||||||
|
def encrypt(data, password)
|
||||||
|
f = Fernet(_get_key(password))
|
||||||
|
return f.encrypt(data.encode()).decode()
|
||||||
|
|
||||||
|
|
||||||
|
def decrypt(data, password)
|
||||||
|
f = Fernet(_get_key(password))
|
||||||
|
return f.decrypt(data.encode()).decode()
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,12 @@ if __name__ == '__main__':
|
||||||
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, parent_dir)
|
sys.path.insert(0, parent_dir)
|
||||||
|
|
||||||
|
# ~ v2
|
||||||
|
from controllers import utils
|
||||||
|
|
||||||
|
# ~ v1
|
||||||
from controllers import util
|
from controllers import util
|
||||||
|
|
||||||
from settings import log, DEBUG, VERSION, PATH_CP, COMPANIES, PRE, CURRENT_CFDI, \
|
from settings import log, DEBUG, VERSION, PATH_CP, COMPANIES, PRE, CURRENT_CFDI, \
|
||||||
INIT_VALUES, DEFAULT_PASSWORD, DECIMALES, IMPUESTOS, DEFAULT_SAT_PRODUCTO, \
|
INIT_VALUES, DEFAULT_PASSWORD, DECIMALES, IMPUESTOS, DEFAULT_SAT_PRODUCTO, \
|
||||||
CANCEL_SIGNATURE, PUBLIC, DEFAULT_SERIE_TICKET, CURRENT_CFDI_NOMINA, \
|
CANCEL_SIGNATURE, PUBLIC, DEFAULT_SERIE_TICKET, CURRENT_CFDI_NOMINA, \
|
||||||
|
@ -4336,7 +4340,7 @@ class Facturas(BaseModel):
|
||||||
importe = round(cantidad * precio_final, DECIMALES)
|
importe = round(cantidad * precio_final, DECIMALES)
|
||||||
|
|
||||||
if use_packing:
|
if use_packing:
|
||||||
product['empaques'] = util.round_up(
|
product['empaques'] = utils.round_up(
|
||||||
cantidad / float(p.cantidad_empaque))
|
cantidad / float(p.cantidad_empaque))
|
||||||
|
|
||||||
product['cantidad'] = cantidad
|
product['cantidad'] = cantidad
|
||||||
|
|
|
@ -48,7 +48,7 @@ except ImportError:
|
||||||
|
|
||||||
DEBUG = DEBUG
|
DEBUG = DEBUG
|
||||||
VERSION = '1.28.0'
|
VERSION = '1.28.0'
|
||||||
EMAIL_SUPPORT = ('soporte@empresalibre.net',)
|
EMAIL_SUPPORT = ('soporte@empresalibre.mx',)
|
||||||
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)
|
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)
|
||||||
|
|
||||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
Loading…
Reference in New Issue