@@ -106,6 +106,11 @@ class CertificateError(SigverError):
106
106
pass
107
107
108
108
109
+ def read_file (* args , ** kwargs ):
110
+ with open (* args , ** kwargs ) as handler :
111
+ return handler .read ()
112
+
113
+
109
114
def rm_xmltag (statement ):
110
115
try :
111
116
_t = statement .startswith (XMLTAG )
@@ -540,7 +545,7 @@ def pem_format(key):
540
545
541
546
542
547
def import_rsa_key_from_file (filename ):
543
- return RSA .importKey (open (filename , 'r' ). read ( ))
548
+ return RSA .importKey (read_file (filename , 'r' ))
544
549
545
550
546
551
def parse_xmlsec_output (output ):
@@ -648,11 +653,13 @@ def read_cert_from_file(cert_file, cert_type):
648
653
:param cert_type: The certificate type
649
654
:return: A base64 encoded certificate as a string or the empty string
650
655
"""
656
+
657
+
651
658
if not cert_file :
652
659
return ""
653
660
654
661
if cert_type == "pem" :
655
- line = open (cert_file ). read ( ).split ("\n " )
662
+ line = read_file (cert_file ).split ("\n " )
656
663
if line [0 ] == "-----BEGIN CERTIFICATE-----" :
657
664
line = line [1 :]
658
665
elif line [0 ] == "-----BEGIN PUBLIC KEY-----" :
@@ -672,7 +679,7 @@ def read_cert_from_file(cert_file, cert_type):
672
679
return "" .join (line )
673
680
674
681
if cert_type in ["der" , "cer" , "crt" ]:
675
- data = open (cert_file ). read ( )
682
+ data = read_file (cert_file )
676
683
return base64 .b64encode (str (data ))
677
684
678
685
0 commit comments