Skip to content

Commit 87d26a4

Browse files
Remove unnecesary validations (#20)
Error handling is managed in at_client.py so there is no need to validate again errors in other parts of the code Signed-off-by: Pascal Hernandez <[email protected]>
1 parent 7dd9d81 commit 87d26a4

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/nrfcredstore/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ def exec_cmd(args, credstore):
8989
ct = CredType[args.type]
9090
if credstore.delete(args.tag, ct):
9191
print(f'{ct.name} in secure tag {args.tag} deleted')
92-
else:
93-
raise RuntimeError('delete failed')
9492
elif args.subcommand=='generate':
9593
credstore.keygen(args.tag, args.file, args.attributes)
9694
print(f'New private key generated in secure tag {args.tag}')

src/nrfcredstore/credstore.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ def __init__(self, tag: int, type: int, sha: str):
2626
self.type = CredType(type)
2727
self.sha = sha
2828

29-
def is_ok(response_lines):
30-
return not any("ERROR" in line for line in response_lines)
31-
3229
class CredStore:
3330
def __init__(self, at_client):
3431
self.at_client = at_client
@@ -80,7 +77,7 @@ def write(self, tag: int, type: CredType, file: io.TextIOBase):
8077
if type == CredType.ANY:
8178
raise ValueError
8279
cert = file.read().rstrip()
83-
return is_ok(self.at_client.at_command(f'AT%CMNG=0,{tag},{type.value},"{cert}"'))
80+
return self.at_client.at_command(f'AT%CMNG=0,{tag},{type.value},"{cert}"')
8481

8582
def delete(self, tag: int, type: CredType):
8683
"""Delete a credential from the modem
@@ -90,7 +87,7 @@ def delete(self, tag: int, type: CredType):
9087

9188
if type == CredType.ANY:
9289
raise ValueError
93-
return is_ok(self.at_client.at_command(f'AT%CMNG=3,{tag},{type.value}'))
90+
return self.at_client.at_command(f'AT%CMNG=3,{tag},{type.value}')
9491

9592
def keygen(self, tag: int, file: io.BufferedIOBase, attributes: str = ''):
9693
"""Generate a new private key and return a certificate signing request in DER format"""

tests/test_credstore.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def test_list_fail(self, cred_store, at_error):
107107
cred_store.list()
108108

109109
def test_delete_success(self, cred_store, ok_resp):
110-
assert cred_store.delete(567890, CredType(1))
110+
response = cred_store.delete(567890, CredType(1))
111+
assert len(response) == 0
111112
self.at_client.at_command.assert_called_with('AT%CMNG=3,567890,1')
112113

113114
def test_delete_fail(self, cred_store, at_error):
@@ -123,7 +124,8 @@ def test_write_success(self, cred_store, ok_resp):
123124
dGVzdA==
124125
-----END CERTIFICATE-----'''
125126
fake_file = io.StringIO(cert_text)
126-
assert cred_store.write(567890, CredType.CLIENT_KEY, fake_file)
127+
response = cred_store.write(567890, CredType.CLIENT_KEY, fake_file)
128+
assert len(response) == 0
127129
self.at_client.at_command.assert_called_with(f'AT%CMNG=0,567890,2,"{cert_text}"')
128130

129131
def test_write_fail(self, cred_store, at_error):

0 commit comments

Comments
 (0)