Code Monkey home page Code Monkey logo

base64-url's Introduction

Hi, welcome to my Github pages.

Things Related to My Projects

Rust JavaScript TypeScript Java C PHP Golang Bash

Ubuntu Server Linux Mint Android Windows

Tokio Rocket Axum napi-rs iced Node.js Webpack Express Fastify NestJS + Fastify Bootstrap Vite Vue.js Handlebars Tera Sass Nginx Apache httpd Docker

MySQL SQLite MongoDB Redis

base64-url's People

Contributors

dependabot[bot] avatar magiclen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

base64-url's Issues

decode_to_slice requires a global_allocator to be configured

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

Fails to correctly encode "aswf!@#$%^&*()"

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.

Set decode length in bits

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.