Commit e9a8394
authored
Support allocation free usage of bcrypt (#95)
* Truncate password into stack buffer instead of vec
This doesn't need to be dynamically allocated. The logic is relatively
simple - ensure it starts as a null terminated string, but truncate at
72 bytes. We can simply zero fill a stack buffer (thereby ensuring the
last byte is a null byte) and then copy into it up until that last byte
if we are not truncating, and including the last byte if we are,
preserving the previous behavior with no dynamic allocation.
* Update HashParts to be optionally alloc free
HashParts previously stored base64-encoded salt and hash as heap-allocated
Strings. They are now stored as raw bytes ([u8; 16] and [u8; 23]).
Encoding and decoding of base64 happens with slices now rather than
internally allocating as well.
This change aims to provide a way for callers to avoid dynamic
allocation entirely, if desired, while maintaining existing public
method signatures for backwards compatibility.
It adds similar methods to public methods that already existed that
allow callers to do the same thing (retreive salt, get bcrypt format
string, etc.) in allocation free ways.
* Add alloc-free variants for all public hash funcs
Adds allocation free variants of all public hashing functions, to
provide a mechanism for users to use bcrypt fully alloc free if they
want.
* Remove Vec usage in split_hash
This removes a vec usages (just used to split the incoming hash string
into it's parts) with a solution that avoids allocating.1 parent 217eab3 commit e9a8394
1 file changed
Lines changed: 255 additions & 81 deletions
0 commit comments