diff options
author | Magnus Ahltorp <map@kth.se> | 2015-01-28 13:42:06 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2015-02-20 14:12:47 +0100 |
commit | 832dba2e1cd4e6e6ff9e8ea7afa98eebb44595e5 (patch) | |
tree | 5ad6f45daf3a4fd66c5d3c576dda857e147210ff /tools/certtools.py | |
parent | 7d9413dcea9645cfa0f8887ac7536682ff5777f0 (diff) |
Move hardcoded merge parameters to command line
Diffstat (limited to 'tools/certtools.py')
-rw-r--r-- | tools/certtools.py | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/tools/certtools.py b/tools/certtools.py index cbb4ff7..af94fb8 100644 --- a/tools/certtools.py +++ b/tools/certtools.py @@ -42,22 +42,31 @@ def get_cert_info(s): result[key] = value return result -def get_certs_from_file(certfile): - certs = [] - cert = "" - incert = False - for line in open(certfile): +def get_pemlike(filename, marker): + entries = [] + entry = "" + inentry = False + + for line in open(filename): line = line.strip() - if line == "-----BEGIN CERTIFICATE-----": - cert = "" - incert = True - elif line == "-----END CERTIFICATE-----": - certs.append(base64.decodestring(cert)) - incert = False - elif incert: - cert += line - return certs + if line == "-----BEGIN " + marker + "-----": + entry = "" + inentry = True + elif line == "-----END " + marker + "-----": + entries.append(base64.decodestring(entry)) + inentry = False + elif inentry: + entry += line + return entries + +def get_certs_from_file(certfile): + return get_pemlike(certfile, "CERTIFICATE") + +def get_eckey_from_file(keyfile): + keys = get_pemlike(keyfile, "EC PRIVATE KEY") + assert len(keys) == 1 + return keys[0] def get_root_cert(issuer): accepted_certs = \ |