base64_url decode long string got run-time error #33
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
need more info
need verification for fix
not so hard
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-tplgy/cppcodec#33
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hello,
First of all, thank you for your lib!
I have run-time error when trying to decode the below:
std::string mydecode = base64_url::decode<std::string>("EtwFwjS7cNIZjXcufbR6r6mg8s1_e-jfObtENsgjQamDuuJZlT7lpReGgtl1bac77Lk0IDPNyFkhR-Rdv9kDBYcERUWMt_WBrqErnuciol09BReP7UCwfgwFftv3FMjRE29WpXInQ4vfFtbyd6YLN5AKAVZ-r5EcBYVdnjqli4zDR8TCKOPo1jhV5g3w43PPVSsc3KJS_C-i7SlJoGAjfWD97mL6kTYnoivbh_f61Vch9jS_zxslmqD_If0ZM7VtPxFE0oIPlbAka-OchPjrdEwF1lQqsmB1mE8zRF3yvPrz8tDjic3EQEjr-i6_F4NHJNg6tUq466DozbWct2ZrQdh70I764VrcktS1M93Rm5KjzEMUv7MmFjb03sWw7j2iVuLWgir4BqxGdS8E6yo8Vw12xk0pjOAaeuE_yzRRh_k_yAH2BkPFc7cibOYWcfOBL8-fd3PAbmSTm1BRSmZA3Epo9W93zVB6yazqk8YdvRmAde6WgPP8z2jckrLwpK88TySatMllkuxvpto0ZvdSDXNw2SfDuFrmxWPTsk0BHpS5jxjhV4R_FPyzTUAGijS_FJsfwXn-G1ii8AsDvyVuq3Om0cQmJ-mNC8pqTXvTvso556hIm1jHb-mIfhiwZk4gJONTqqQ_NPTA1vl6Omzznbl_BKSLlc4OcdIGqEdRll4NNjoxdVqWlNaS4O9L0C2UfEqK7NWAPymiLBCFYxSWsbul9seiZvS_UhV3I7lDDwy-40mQV9UN0wXV0cRZVpr_YrRvE9-SWtpyb3ZOi5y52d6oP6MeMe-kRvQRF8OkXsw-oXhkpOpMzcKi2xq9Q4k6Vuvme5s1PHCN8gAC4fJ4jm2H_XsJA6qFyDfXAdvcu6Z_GINje-sPRFc7Gpl88tbmPOAT-k0a-xeGMSd8h5xYIXcnrGjqXHFRxl_qPA");Could you help me out?
I don't think your string is padded correctly. Try
std::string mydecode = base64_url_unpadded::decode<std::string>("EtwFwjS7cNIZjXcufbR6r6mg8s1_e-jfObtENsgjQamDuuJZlT7lpReGgtl1bac77Lk0IDPNyFkhR-Rdv9kDBYcERUWMt_WBrqErnuciol09BReP7UCwfgwFftv3FMjRE29WpXInQ4vfFtbyd6YLN5AKAVZ-r5EcBYVdnjqli4zDR8TCKOPo1jhV5g3w43PPVSsc3KJS_C-i7SlJoGAjfWD97mL6kTYnoivbh_f61Vch9jS_zxslmqD_If0ZM7VtPxFE0oIPlbAka-OchPjrdEwF1lQqsmB1mE8zRF3yvPrz8tDjic3EQEjr-i6_F4NHJNg6tUq466DozbWct2ZrQdh70I764VrcktS1M93Rm5KjzEMUv7MmFjb03sWw7j2iVuLWgir4BqxGdS8E6yo8Vw12xk0pjOAaeuE_yzRRh_k_yAH2BkPFc7cibOYWcfOBL8-fd3PAbmSTm1BRSmZA3Epo9W93zVB6yazqk8YdvRmAde6WgPP8z2jckrLwpK88TySatMllkuxvpto0ZvdSDXNw2SfDuFrmxWPTsk0BHpS5jxjhV4R_FPyzTUAGijS_FJsfwXn-G1ii8AsDvyVuq3Om0cQmJ-mNC8pqTXvTvso556hIm1jHb-mIfhiwZk4gJONTqqQ_NPTA1vl6Omzznbl_BKSLlc4OcdIGqEdRll4NNjoxdVqWlNaS4O9L0C2UfEqK7NWAPymiLBCFYxSWsbul9seiZvS_UhV3I7lDDwy-40mQV9UN0wXV0cRZVpr_YrRvE9-SWtpyb3ZOi5y52d6oP6MeMe-kRvQRF8OkXsw-oXhkpOpMzcKi2xq9Q4k6Vuvme5s1PHCN8gAC4fJ4jm2H_XsJA6qFyDfXAdvcu6Z_GINje-sPRFc7Gpl88tbmPOAT-k0a-xeGMSd8h5xYIXcnrGjqXHFRxl_qPA");or
std::string mydecode = base64_url::decode<std::string>("EtwFwjS7cNIZjXcufbR6r6mg8s1_e-jfObtENsgjQamDuuJZlT7lpReGgtl1bac77Lk0IDPNyFkhR-Rdv9kDBYcERUWMt_WBrqErnuciol09BReP7UCwfgwFftv3FMjRE29WpXInQ4vfFtbyd6YLN5AKAVZ-r5EcBYVdnjqli4zDR8TCKOPo1jhV5g3w43PPVSsc3KJS_C-i7SlJoGAjfWD97mL6kTYnoivbh_f61Vch9jS_zxslmqD_If0ZM7VtPxFE0oIPlbAka-OchPjrdEwF1lQqsmB1mE8zRF3yvPrz8tDjic3EQEjr-i6_F4NHJNg6tUq466DozbWct2ZrQdh70I764VrcktS1M93Rm5KjzEMUv7MmFjb03sWw7j2iVuLWgir4BqxGdS8E6yo8Vw12xk0pjOAaeuE_yzRRh_k_yAH2BkPFc7cibOYWcfOBL8-fd3PAbmSTm1BRSmZA3Epo9W93zVB6yazqk8YdvRmAde6WgPP8z2jckrLwpK88TySatMllkuxvpto0ZvdSDXNw2SfDuFrmxWPTsk0BHpS5jxjhV4R_FPyzTUAGijS_FJsfwXn-G1ii8AsDvyVuq3Om0cQmJ-mNC8pqTXvTvso556hIm1jHb-mIfhiwZk4gJONTqqQ_NPTA1vl6Omzznbl_BKSLlc4OcdIGqEdRll4NNjoxdVqWlNaS4O9L0C2UfEqK7NWAPymiLBCFYxSWsbul9seiZvS_UhV3I7lDDwy-40mQV9UN0wXV0cRZVpr_YrRvE9-SWtpyb3ZOi5y52d6oP6MeMe-kRvQRF8OkXsw-oXhkpOpMzcKi2xq9Q4k6Vuvme5s1PHCN8gAC4fJ4jm2H_XsJA6qFyDfXAdvcu6Z_GINje-sPRFc7Gpl88tbmPOAT-k0a-xeGMSd8h5xYIXcnrGjqXHFRxl_qPA==");ohh, I see..
Could you make it auto detecting whether it was padded or not before decoding?
because when one person mixed padded and no-padded string, to know exactly which one to use at run-time is troublesome.
Something like below:
function encode(string, bool want_to_pad = false); -->option to pad
function decode(string); --> auto detect padding and decode
base64_url_unpaddedaccepts padding, but doesn't require it (in your words, "auto detect padding"). I believe that's what you're asking for for decode().Regarding encode(), adding a run-time option is made harder by the architectural choices for this project. On one hand, I use the want_to_pad option (in the code:
generates_padding()) at compile time to decide whether padding should even be part of the code base. On the other hand, cppcodec provides the same API for a number of different codecs - some are stricter about padding and don't allow it at all, it would be wrong for those to include it in the API. Both of those would be significant changes and I'm not sure that it's a good trade-off as opposed to just using different codec names.Please let me know how you would change the documentation so that you wouldn't run into the same issue if you did it again from scratch.
Thank you for your answer. I think a simple recommendation in Readme page is enough.
Some thing like: If you don't know whether the encoded message was padded or not, then just use base64_url_unpadded::decode because it works on both situations.