diff options
author | Simon Warta <[email protected]> | 2017-04-18 22:47:57 +0200 |
---|---|---|
committer | Simon Warta <[email protected]> | 2017-04-18 23:33:41 +0200 |
commit | 6d8d19dcb8dd52fa7b4bd706e909f2386373e89f (patch) | |
tree | 65051da2a2dc01478add699c842ccfce7a35b389 /configure.py | |
parent | f054f47e1edabe2bf680b7a3fe183a5e4821f8e4 (diff) |
Improve error handling for HouseEccCurve
Diffstat (limited to 'configure.py')
-rwxr-xr-x | configure.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/configure.py b/configure.py index d3b7b10d2..7072584fd 100755 --- a/configure.py +++ b/configure.py @@ -1720,8 +1720,8 @@ class MakefileListsGenerator(object): class HouseEccCurve(object): def __init__(self, house_curve): p = house_curve.split(",") - if len(p) < 4: - raise UserError('Too few parameters to --house-curve') + if len(p) != 4: + raise UserError('--house-curve must have 4 comma separated parameters. See --help') # make sure TLS curve id is in reserved for private use range (0xFE00..0xFEFF) curve_id = int(p[3], 16) if curve_id < 0xfe00 or curve_id > 0xfeff: @@ -1730,7 +1730,7 @@ class HouseEccCurve(object): self._defines = [ 'HOUSE_ECC_CURVE_NAME \"' + p[1] + '\"', 'HOUSE_ECC_CURVE_OID \"' + p[2] + '\"', - 'HOUSE_ECC_CURVE_PEM ' + self._read_pem(filename=p[0]), + 'HOUSE_ECC_CURVE_PEM ' + self._read_pem(filepath=p[0]), 'HOUSE_ECC_CURVE_TLS_ID ' + hex(curve_id), ] @@ -1738,12 +1738,15 @@ class HouseEccCurve(object): return self._defines @staticmethod - def _read_pem(filename): - with open(filename) as f: - lines = [line.rstrip() for line in f] - for ndx, _ in enumerate(lines): - lines[ndx] = ''.join(('\"', lines[ndx], '\" \\', '\n')) - return ''.join(lines) + def _read_pem(filepath): + try: + with open(filepath) as f: + lines = [line.rstrip() for line in f] + for ndx, _ in enumerate(lines): + lines[ndx] = ''.join(('\"', lines[ndx], '\" \\', '\n')) + return ''.join(lines) + except IOError: + raise UserError("Error reading file '%s'" % filepath) def create_template_vars(source_paths, build_config, options, modules, cc, arch, osinfo): |