Skip to content

Commit 8cd2333

Browse files
authored
Merge pull request #28 from netosjb/fix-password-to-binary
[FIX] Passphrase Warning
2 parents 8ec6f16 + a868275 commit 8cd2333

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/erpbrasil/assinatura/certificado.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Certificado(object):
1919
def __init__(self, arquivo, senha, raise_expirado=True):
2020
"""Permite informar um arquivo PFX binario ou o path do arquivo"""
2121

22-
self._senha = senha
22+
self._senha = self._encode_senha(senha)
2323

2424
try:
2525
try:
@@ -66,7 +66,7 @@ def _load_key_and_certificates(self):
6666
"""
6767
return load_key_and_certificates(
6868
data=self._arquivo,
69-
password=self._senha.encode(),
69+
password=self._senha,
7070
backend=default_backend()
7171
)
7272

@@ -113,6 +113,11 @@ def pkcs12(self):
113113
"""Retorna o arquivo pfx no formato binario pkc12"""
114114
return self._pkcs12
115115

116+
def _encode_senha(self, senha):
117+
if type(senha) == str:
118+
return senha.encode()
119+
else:
120+
return senha
116121

117122
class ArquivoCertificado(object):
118123
""" Classe para ser utilizada quando for necessário salvar o arquivo

tests/test_erpbrasil_certificado.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ def test_abertura_arquivo_temporariamente(self):
4343
self.assertTrue(os.path.exists(caminho_cert))
4444
self.assertFalse(os.path.exists(caminho_key))
4545
self.assertFalse(os.path.exists(caminho_cert))
46+
47+
def test_senha(self):
48+
senha = self.certificado._encode_senha("123456")
49+
self.assertTrue(type(senha) is bytes)
50+
senha = self.certificado._encode_senha("123456".encode())
51+
self.assertTrue(type(senha) is bytes)

0 commit comments

Comments
 (0)