crypto_knowledge: improve return values for get_inner_algorithm()

Return a ValueError exception instead of None if the given algorithm is
not a composed one.

Signed-off-by: Valerio Setti <[email protected]>
This commit is contained in:
Valerio Setti
2026-09-09 10:13:18 +02:00
parent 36054361c4
commit edeb57f200
@@ -505,10 +505,13 @@ class Algorithm:
return True
def get_inner_algorithm(self) -> "Algorithm":
"""Given an algorithm composed as outer_alg(inner_alg) return inner_alg."""
"""Given an algorithm composed as outer_alg(inner_alg) return inner_alg.
Raise ValueError if the algorithm is not a composed one.
"""
m = re.match(r'\w+\(\s*(.*)\)\Z', self.expression)
if not m:
return None
raise ValueError('Not a composed algorithm: ' + self.expression)
inner_alg = m.group(1)
return Algorithm(inner_alg)