]> git.earman.xyz Git - sensor-watch.git/commit
faces/totp: improve memory usage
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Sun, 17 Mar 2024 22:32:27 +0000 (19:32 -0300)
committerMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Sun, 17 Mar 2024 23:48:54 +0000 (20:48 -0300)
commitdf38c262b80151af06f15e6a1a8899c51dec438e
tree80eb38c1b95cbd9ced5bb2c3b4c2d7597bd81a60
parent955ac94de3afcad4e79bcf16e8fecd512a3dddca
faces/totp: improve memory usage

The TOTP face is working in the simulator but fails on the real hardware
when loaded with lots of codes, just like the LFS version.
This is likely caused by the recent refactoring of the TOTP face
which introduced a declarative credential interface for ease of use.
That's accomplished by decoding the secrets at runtime which increases
the RAM requirements. Users are likely hitting memory limits.

In order to mitigate this, the algorithm is changed from decoding
all of the secrets only once during initialization to on the fly
decoding of the secret for the current TOTP credential only.
This converts this face's dynamic memory usage from O(N) to O(1)
at the cost of memory management when switching faces and credentials
which could impact power consumption. Issue is confirmed fixed by
author of issue who has tested it on real hardware. Fixes #384.

Due to variable key sizes, the memory cannot be statically allocated.
Perhaps there's a maximum key size that can serve as worst case?

Also took this opportunity to restructure the code a bit.
Also added code to check for memory allocation failure.

Reported-by: madhogs <59648482+madhogs@users.noreply.github.com>
Fixed-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Tested-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Tested-on-hardware-by: madhogs <59648482+madhogs@users.noreply.github.com>
Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
GitHub-Issue: https://github.com/joeycastillo/Sensor-Watch/issues/384
movement/watch_faces/complication/totp_face.c
movement/watch_faces/complication/totp_face.h