diff options
author | Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> | 2024-03-18 10:41:06 -0300 |
---|---|---|
committer | Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com> | 2024-03-18 11:40:55 -0300 |
commit | 3f850d79c8b0b4da5c1b8854f2e6437ca163edc4 (patch) | |
tree | e4fabde54328b8ac5bbab443dc2af4e77e30f0ff /movement/lib/TOTP/example.c | |
parent | df38c262b80151af06f15e6a1a8899c51dec438e (diff) | |
download | Sensor-Watch-3f850d79c8b0b4da5c1b8854f2e6437ca163edc4.tar.gz Sensor-Watch-3f850d79c8b0b4da5c1b8854f2e6437ca163edc4.tar.bz2 Sensor-Watch-3f850d79c8b0b4da5c1b8854f2e6437ca163edc4.zip |
faces/totp: remove dynamic memory allocation
Allocate an unlimited extent 128 byte buffer once during setup
instead of allocating and deallocating repeatedly. A static buffer
was not used because it fails to be reentrant and prevents multiple
instances of the watch face to be compiled by the user.
The advantage is the complete prevention of memory management errors,
improving the reliability of the watch. It also eliminates the overhead
of the memory allocator itself since malloc is not free.
The disadvantage is a worst case default size of 128 bytes was required,
meaning about 90 bytes will be wasted in the common case since most keys
are not that big. This can be overridden by the user via preprocessor.
The key lengths are checked on TOTP watch face initialization
and if any key is found to be too large to fit the buffer
it is turned off and the label and ERROR is displayed instead.
The base32 encoded secrets are decoded dynamically to the buffer
at the following times:
- Face enters the foreground
- User switches TOTP code
Therefore, there is still some extra runtime overhead
that can still be eliminated by code generation.
This will be addressed in future commits.
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-Pull-Request: https://github.com/joeycastillo/Sensor-Watch/pull/385
Diffstat (limited to 'movement/lib/TOTP/example.c')
0 files changed, 0 insertions, 0 deletions