Comments (7)
Did you allocate the memory for the output buffer in char* out
? The caller is responsible for supplying a memory buffer of "sufficient" size. Sufficient here means at least 4/3 of the input size, because that's the size that the Base64 encoding will expand to.
from base64.
My bad I did not allocate memory. Thanks for the quick reply.
Would I able to do base64 encode using this library and then decode the encoded data using python base64 decode ?
Is there any python wrappers provided in this library?
I have a python application which will receive the encoded data from a c++ application hence wanted to confirm on this.
from base64.
Would I able to do base64 encode using this library and then decode the encoded data using python base64 decode ?
Yes, Base64 encoding is standardized and is implementation independent.
Is there any python wrappers provided in this library?
No, this is a pure C library.
from base64.
Is there any python wrappers provided in this library?
No, this is a pure C library.
While this library does not provide a python wrapper, I do maintain one: https://github.com/mayeut/pybase64
from base64.
Did you allocate the memory for the output buffer in
char* out
? The caller is responsible for supplying a memory buffer of "sufficient" size. Sufficient here means at least 4/3 of the input size, because that's the size that the Base64 encoding will expand to.
Should this memory allocation be enough ?
char* out = (char*)malloc(get_data_size()*sizeof(char)*(4/3));
// get_data_size() returns the size of the original frame handle which I am trying to encode
Is it responsibility of the user to free the allocated memory buffer ?
from base64.
4/3 of the original size should be enough, but it's probably safer to add 4 bytes or so for the optional base64 end markers or if you expect to add a null terminator at some point.
Also, your code as written has a bug. (4/3)
will evaluate to 1
because it's using integer division. sizeof (char)
is guaranteed to be 1 per the C standard, so it doesn't add much to use it in the expression. You could do something like this (untested):
const size_t size = get_data_size();
uint8_t *out;
// Allocate memory for the output buffer.
if ((out = malloc(size * 4 / 3 + 4)) == NULL) {
// Handle the malloc error
perror("malloc");
return false;
}
// Do something with the buffer.
...
// Free the memory.
free(out);
return true;
Just a quick example of course. Yes, the user is responsible for calling free()
on any memory they allocate. That's the drawback of C's manual memory handling.
from base64.
Sorry for the delayed response.
Thanks for your suggestion on the usage.
from base64.
Related Issues (20)
- bin/base64: modernize the demo program
- Add a macro to calculate encoded size from raw size and vice versa
- Investigate `gf2p8affineqb` for the shuffle step
- enc: asm: add memory and flags as clobbers
- Integrate with google/oss-fuzz for continuous fuzz testing
- Create release 0.5.1
- Codec detection doesnโt work in test_base64 on musl libc HOT 3
- v0.5.1 breaks `base64 -d` on Alpine Linux (musl libc) HOT 15
- Build of 0.5.1 broken with MinGW HOT 15
- I made a online base64 decoder tool. We can use it HOT 1
- Simplify codepath selection HOT 4
- build failure using mingw32: `error: 'asm' operand has impossible constraints` HOT 4
- CMakeLists: update version to 0.5.2
- bin/base64: add command line options for decoding
- Add `BASE64_FORCE_INLINE` macro to always inline inner loop functions
- Decoding error on Windows (CRLF?) HOT 18
- Codepage error on Windows HOT 2
- Build fails on macOS: `make: objcopy: No such file or directory` HOT 2
- Add installation guide for lib HOT 2
- error: implicit declaration of function 'bit' is invalid in C99 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from base64.