-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addition of encoder module with bas64 and hex encode/decode as per #925 #1072
Conversation
This taught me that the dev environment runs with chars being unsigned by default, Interesting... |
Yes, they are, but where the arithmetic goes wrong if they happen to be signed (e.g. x>>4) I specify the unsignedness explicitly. Still this works as we discussed the legacy |
Your base64 code relies on the unsignedness of the char (and also on the fact that CHAR_MIN == 0) |
@@ -37,7 +37,29 @@ static int crypto_sha1( lua_State* L ) | |||
return 1; | |||
} | |||
|
|||
#ifdef LUA_USE_MODULES_ENCODER | |||
static int call_endcoder( lua_State* L, const char *function ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to call this call_endcoder
with a d
, or just call_encoder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup you are right. Wonder why I didn't get a compile warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you autocompleted all other references the same :)
Philip, two of the routines are essentially copied from |
@jmattsson Johny, have you any comments before I do this rework. I'd like to sweep all feedback into this, rather have to do another circle around. |
|
||
#### Example | ||
```lua | ||
print(encoder.toBase64(cyrpto.hash("sha1","abc"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "crypto.hash"
I haven't got time to investigate for myself right now, but is there any chance of re-using the ROM functions for base64 instead of needing our own? I think it'll depend on how/if they allocate memory.
|
Good suggestion. I'll take a look. If easy to do, I'll also add this to the |
They use the ROM mem_malloc / mem_free rather than the SDK's RTOS compatible pvPortMalloc a.k.a. os_malloc that is used in the app. I assume that these aren't mix and match. |
I seem to recall having had things crash & burn (literally and figuratively, correspondingly) when trying to do said mix & match, so no, I'd recommend against it. Unless you want to copy the base64 routines from rom into iram dynamically and hot-patch the alloc/free calls to point to something more compatible... ;) No further comments from me then, ping me when you've done the next round here and I can merge. |
Not worth it. The generated code saving just isn't worth this complexity. If we want to save .text space then there are lower hanging fruit to go after. |
I really wasn't serious with that suggestion, Terry! With the amount of finicky stuff one would have to get right (like, where do I even load this to in iram without clobbering anything?) would with near certainty result in an increase of code size rather than a decrease. I'll take the maintainability of regular code over meta-code, thank you! |
Sorry Johny, I picked up a flea from some friends dog and woke up in the middle of the night with my leg in the middle of being a lunch meal for the flea and its kids and itching like hell -- so a shower and the guest bedroom later, I am now clearing off issues whilst the itching subsides. My brain isn't working too well! |
I've updated the files to echo the review comments. I've also fix a bug with the end packet base64 decode that my test vectors threw up. Perhaps one of the committers could merge this. 😄 |
Addition of encoder module with base64 and hex encode/decode as per #925
Thanks Terry! |
See Issue #925 for discussions on this.