Hi, welcome to my Github pages.
magiclen / base64-url Goto Github PK
View Code? Open in Web Editor NEWBase64 encode, decode, escape and unescape for URL applications.
License: MIT License
Base64 encode, decode, escape and unescape for URL applications.
License: MIT License
I'm using v2.0.0, with the following Cargo.toml config:
[dependencies]
base64-url = {version= "2.0.0", default-features = false}
And the code is using this one function:
base64_url::decode_to_slice(...)
When I use this in a build that has no global_allocator, I see the following error:
error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait
Using base64-simd as a backend can provide a performance boost for "free".
Benchmarks: docs/benches-v050.md
See https://github.com/magiclen/base64-url/blob/master/Cargo.toml#L21
Its no longer possible to enable the std feature on the base64
dependency with a feature on this crate. Is it expected that all consumers of base64-url
that want to use base64/std
must explicitly state base64
as a dependency?
base64_url::encode("aswf!@#$%^&*()")
returns "YXN3ZiFAIyQlXiYqKCk"
Attempting to decode this with Linux' base64 binary fails:
$ echo "YXN3ZiFAIyQlXiYqKCk" | base64 -d
aswf!@#$%^&*()base64: invalid input
This is the correct base64 encoding (trailing '='
!):
$ echo -n 'aswf!@#$%^&*()' | base64
YXN3ZiFAIyQlXiYqKCk=
The base64-crate correctly encodes the string, so I don't know where base64_url goes wrong.
The following code to decode a u64 from base64 works fine but is quite ugly:
let mut array = [0u8; 9];
base64_url::decode_to_slice(str_rep, &mut array).expect("Not a valid base64 encoding");
u64::from_le_bytes(array[..8].try_into().unwrap())
The problem here is that the encoded u64 is 11 characters which amounts to 66 bits, not 64. Ideally, I would like to have a decode function that can set the length explicitly or detects it based on the size of the slice.
For example, this would look much nicer:
let mut array = [0u8; std::mem::size_of::<u64>()];
base64_url::decode_to_slice_with_length(str_rep, &mut array, u64::BITS).expect("Not a valid base64 encoding");
u64::from_le_bytes(array)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.