@@ -106,6 +106,11 @@ class CertificateError(SigverError):
106106 pass
107107
108108
109+ def read_file (* args , ** kwargs ):
110+ with open (* args , ** kwargs ) as handler :
111+ return handler .read ()
112+
113+
109114def rm_xmltag (statement ):
110115 try :
111116 _t = statement .startswith (XMLTAG )
@@ -540,7 +545,7 @@ def pem_format(key):
540545
541546
542547def import_rsa_key_from_file (filename ):
543- return RSA .importKey (open (filename , 'r' ). read ( ))
548+ return RSA .importKey (read_file (filename , 'r' ))
544549
545550
546551def parse_xmlsec_output (output ):
@@ -648,11 +653,13 @@ def read_cert_from_file(cert_file, cert_type):
648653 :param cert_type: The certificate type
649654 :return: A base64 encoded certificate as a string or the empty string
650655 """
656+
657+
651658 if not cert_file :
652659 return ""
653660
654661 if cert_type == "pem" :
655- line = open (cert_file ). read ( ).split ("\n " )
662+ line = read_file (cert_file ).split ("\n " )
656663 if line [0 ] == "-----BEGIN CERTIFICATE-----" :
657664 line = line [1 :]
658665 elif line [0 ] == "-----BEGIN PUBLIC KEY-----" :
@@ -672,7 +679,7 @@ def read_cert_from_file(cert_file, cert_type):
672679 return "" .join (line )
673680
674681 if cert_type in ["der" , "cer" , "crt" ]:
675- data = open (cert_file ). read ( )
682+ data = read_file (cert_file )
676683 return base64 .b64encode (str (data ))
677684
678685
0 commit comments