Compact 2 format functions to 1

In translate_ciphers.py there were 2 format functions that were
virtually identical and a check was made beforehand to decide
which one to call. Now the check is made inside a single function
to reduce duplicate code

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
This commit is contained in:
Joe Subbiani 2021-07-26 13:33:35 +01:00
parent 15d7124661
commit d16d273a40

View file

@ -97,33 +97,23 @@ def translate_ossl(m_cipher):
return m_cipher
def format_g(m_ciphers):
#ciphers = (re.findall(r"TLS-.+\s*\\", m_ciphers))
m_ciphers = m_ciphers.split()
g_ciphers = []
for i in m_ciphers:
g_ciphers.append(translate_gnu(i))
return " ".join(g_ciphers)
def format_o(m_ciphers):
m_ciphers = m_ciphers.split()
o_ciphers = []
for i in m_ciphers:
o_ciphers.append(translate_ossl(i))
return " ".join(o_ciphers)
def format(mode, ciphers):
ciphers = ciphers.split()
t_ciphers = []
if mode == "g":
for i in ciphers:
t_ciphers.append(translate_gnu(i))
if mode == "o":
for i in ciphers:
t_ciphers.append(translate_ossl(i))
return " ".join(t_ciphers)
def main():
# print command line arguments
if len(sys.argv) <= 2:
exit(1)
if sys.argv[1] == "g":
print(format_g(sys.argv[2]))
exit(0)
elif sys.argv[1] == "o":
print(format_o(sys.argv[2]))
exit(0)
else:
exit(1)
print(format(sys.argv[1], sys.argv[2]))
if __name__ == "__main__":
main()