11import os
22import re
33
4+
45def read_certificate_content (file_path ):
56 """Read and return the complete PEM certificate including headers, removing any extra lines."""
67 with open (file_path , 'r' ) as f :
78 full_text = f .read ()
89 # Extract just the chunk from BEGIN CERTIFICATE to END CERTIFICATE
9- start_idx = full_text .find ("-----BEGIN CERTIFICATE-----" )
10- end_idx = full_text .find ("-----END CERTIFICATE-----" ) + len ("-----END CERTIFICATE-----" )
11- if start_idx == - 1 or end_idx == - 1 :
10+ begin_marker = "-----BEGIN CERTIFICATE-----"
11+ end_marker = "-----END CERTIFICATE-----"
12+ start_idx = full_text .find (begin_marker )
13+ if start_idx == - 1 :
14+ # If not found, just return what we have
15+ return full_text .strip ()
16+ end_pos = full_text .find (end_marker , start_idx )
17+ if end_pos == - 1 :
1218 # If not found, just return what we have
1319 return full_text .strip ()
14- pem_chunk = full_text [start_idx :end_idx ]
20+ pem_chunk = full_text [start_idx :end_pos + len ( end_marker ) ]
1521
1622 cleaned_lines = []
1723 for line in pem_chunk .splitlines ():
@@ -28,12 +34,17 @@ def read_private_key_content(file_path):
2834 with open (file_path , 'r' ) as f :
2935 full_text = f .read ()
3036 # Extract just the chunk from BEGIN PRIVATE KEY to END PRIVATE KEY
31- start_idx = full_text .find ("-----BEGIN PRIVATE KEY-----" )
32- end_idx = full_text .find ("-----END PRIVATE KEY-----" ) + len ("-----END PRIVATE KEY-----" )
33- if start_idx == - 1 or end_idx == - 1 :
37+ begin_marker = "-----BEGIN PRIVATE KEY-----"
38+ end_marker = "-----END PRIVATE KEY-----"
39+ start_idx = full_text .find (begin_marker )
40+ if start_idx == - 1 :
41+ # If not found, just return what we have
42+ return full_text .strip ()
43+ end_pos = full_text .find (end_marker , start_idx )
44+ if end_pos == - 1 :
3445 # If not found, just return what we have
3546 return full_text .strip ()
36- pem_chunk = full_text [start_idx :end_idx ]
47+ pem_chunk = full_text [start_idx :end_pos + len ( end_marker ) ]
3748
3849 cleaned_lines = []
3950 for line in pem_chunk .splitlines ():
@@ -100,4 +111,4 @@ def generate_typescript_file():
100111
101112
102113if __name__ == "__main__" :
103- generate_typescript_file ()
114+ generate_typescript_file ()
0 commit comments