commit ca3c320ef42839f373ff1f9e00d6756a444419d7
parent 713fa00d8626333501895e7350031e22b7ae0ada
Author: ThomasV <thomasv@gitorious>
Date: Fri, 7 Aug 2015 11:39:30 +0200
simplify x509 constructor
Diffstat:
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/lib/interface.py b/lib/interface.py
@@ -201,8 +201,7 @@ class TcpInterface(threading.Thread):
with open(cert_path) as f:
cert = f.read()
try:
- x = x509.X509()
- x.parseBinary(cert)
+ x = x509.X509(cert)
except:
traceback.print_exc(file=sys.stderr)
self.print_error("wrong certificate")
@@ -343,8 +342,7 @@ def check_host_name(peercert, name):
def check_cert(host, cert):
try:
- x = x509.X509()
- x.parseBinary(cert)
+ x = x509.X509(cert)
except:
traceback.print_exc(file=sys.stdout)
return
diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py
@@ -283,8 +283,7 @@ def verify_cert_chain(chain):
cert_num = len(chain)
x509_chain = []
for i in range(cert_num):
- x = x509.X509()
- x.parseBinary(bytearray(chain[i]))
+ x = x509.X509(bytearray(chain[i]))
x509_chain.append(x)
if i == 0:
x.check_date()
diff --git a/lib/x509.py b/lib/x509.py
@@ -49,7 +49,7 @@ class CertificateError(Exception):
class X509(object):
- def parseBinary(self, b):
+ def __init__(self, b):
self.bytes = bytearray(b)
@@ -178,9 +178,8 @@ def load_certificates(ca_path):
s = f.read()
bList = pem.dePemList(s, "CERTIFICATE")
for b in bList:
- x = X509()
try:
- x.parseBinary(b)
+ x = X509(b)
x.check_date()
except BaseException as e:
util.print_error("cert error:", e)