Skip to content

Commit 3c217f3

Browse files
committed
pyopenssl dependent endesive now optional
1 parent 8cd2333 commit 3c217f3

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ pytz>=2016.7
22
cryptography==3.3.2
33
signxml==2.8.2
44
pycrypto==2.6.1
5-
endesive==2.0.1
65
chardet==3.0.4

src/erpbrasil/assinatura/assinatura.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
# coding=utf-8
1+
import logging
22
import signxml
33
from base64 import b64encode
44
from cryptography.hazmat.primitives import hashes
55
from cryptography.hazmat.primitives.asymmetric import padding
6-
from endesive import pdf
76
from lxml import etree
87
from Crypto.PublicKey import RSA
98
from Crypto.Hash import SHA
109
from Crypto.Signature import PKCS1_v1_5
1110
from hashlib import sha1
1211

1312

13+
_logger = logging.getLogger(__name__)
14+
15+
1416
class Assinatura(object):
1517

1618
def __init__(self, certificado):
@@ -126,6 +128,15 @@ def assina_string(self, message):
126128
return signature
127129

128130
def assina_pdf(self, arquivo, dados_assinatura, algoritmo='sha256'):
131+
try:
132+
from endesive import pdf
133+
except ImportError:
134+
_logger.info(
135+
"assina_pdf requires the https://github.com/m32/endesive"
136+
"package but it is not bundled by default"
137+
"to avoid depending on pyopenssl which is deprecated"
138+
)
139+
return False
129140
return pdf.cms.sign(
130141
datau=arquivo,
131142
udct=dados_assinatura,

tests/test_erpbrasil_assinatura_pdf.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# coding=utf-8
2-
1+
import logging
32
import os
43
import tempfile
54
from datetime import datetime
@@ -18,6 +17,8 @@
1817

1918
test_path = os.environ.get('test_path', 'tests/')
2019

20+
_logger = logging.getLogger(__name__)
21+
2122

2223
def test_assinatura_nfe_pdf():
2324
certificado = Certificado(certificado_nfe_caminho, certificado_nfe_senha, raise_expirado=False)
@@ -35,6 +36,16 @@ def test_assinatura_nfe_pdf():
3536
'reason': 'Teste assinatura',
3637
}
3738

39+
try:
40+
from endesive import pdf
41+
except ImportError:
42+
_logger.info(
43+
"skipping test because https://github.com/m32/endesive"
44+
"package but it is not installed. It is not bundled by default"
45+
"to avoid depending on pyopenssl which is deprecated."
46+
)
47+
return False
48+
3849
assinatura = assinador.assina_pdf(
3950
arquivo=arquivo,
4051
dados_assinatura=dados_assinatura,
@@ -61,6 +72,16 @@ def test_assinatura_multipla_pdf():
6172
'reason': 'Teste Assinatura CPF',
6273
}
6374

75+
try:
76+
from endesive import pdf
77+
except ImportError:
78+
_logger.info(
79+
"skipping test because https://github.com/m32/endesive"
80+
"package but it is not installed. It is not bundled by default"
81+
"to avoid depending on pyopenssl which is deprecated."
82+
)
83+
return False
84+
6485
assinatura1 = assinador_ecpf.assina_pdf(
6586
arquivo=arquivo,
6687
dados_assinatura=dados_assinatura,

0 commit comments

Comments
 (0)