All Projects → marshallpierce → Rust Base64

marshallpierce / Rust Base64

Licence: other
base64, in rust

Programming Languages

rust
11053 projects

Labels

Projects that are alternatives of or similar to Rust Base64

react-file-input-previews-base64
This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.
Stars: ✭ 15 (-94.36%)
Mutual labels:  base64
utils.js
👷 🔧 zero dependencies vanilla JavaScript utils.
Stars: ✭ 14 (-94.74%)
Mutual labels:  base64
fast-base64
Fastest base64 on the web, with Wasm + SIMD
Stars: ✭ 23 (-91.35%)
Mutual labels:  base64
vue-base64-file-upload
Upload files as base64 data-uris
Stars: ✭ 77 (-71.05%)
Mutual labels:  base64
swift-extras-base64
Base64 encode and decode without the use of Foundation in pure Swift.
Stars: ✭ 65 (-75.56%)
Mutual labels:  base64
micell
A collection of functions for front-end development
Stars: ✭ 16 (-93.98%)
Mutual labels:  base64
go-checksum
Simple tool to calc Golang module checksum of go.mod and module dir.
Stars: ✭ 45 (-83.08%)
Mutual labels:  base64
dart crypto
[Flutter] 本项目基于flutter_macos_v0.5.8-dev版本采用Dart语言开发。`DYFCryptoProvider`集成了Base64, 32/16 Bits MD5, AES, RSA等算法。(This Flutter project is developed in Dart language based on flutter_macos_v0.5.8-dev. `DYFCryptoProvider` integrates Base64, 32/16 Bits MD5, AES and RSA algorithms.)
Stars: ✭ 30 (-88.72%)
Mutual labels:  base64
nazar
Electronic component detection, identification and recognition system in realtime from camera image using react-native and tensorflow for classification along with Clarifai API with option to search the component details from web with description shown from Octopart fetched from server
Stars: ✭ 25 (-90.6%)
Mutual labels:  base64
secondhand-deal
A campus secondhand trading system based on the vue.js + stylus + koa2 + sequelize ORM + mysql, and typescript is still learning to migrate.🍌
Stars: ✭ 21 (-92.11%)
Mutual labels:  base64
Base62x
Base62x is an alternative approach to Base 64 without symbols in output.
Stars: ✭ 38 (-85.71%)
Mutual labels:  base64
pybase64
Fast Base64 encoding/decoding in Python
Stars: ✭ 84 (-68.42%)
Mutual labels:  base64
jose-simple
Jose-Simple allows the encryption and decryption of data using the JOSE (JSON Object Signing and Encryption) standard.
Stars: ✭ 50 (-81.2%)
Mutual labels:  base64
data-encoding
Efficient and customizable data-encoding functions in Rust
Stars: ✭ 92 (-65.41%)
Mutual labels:  base64
postcss-inline-base64
PostCSS plugin used to replace value inside of url function to base64
Stars: ✭ 23 (-91.35%)
Mutual labels:  base64
BaseNcoding
Library for encoding of binary data into strings using base32, base85, base128 and other algorithms.
Stars: ✭ 42 (-84.21%)
Mutual labels:  base64
UrlBase64
A standards-compliant implementation of web/url-safe base64 encoding and decoding for .NET targets
Stars: ✭ 25 (-90.6%)
Mutual labels:  base64
lzbase62
LZ77(LZSS) based compression algorithm in base62 for JavaScript.
Stars: ✭ 38 (-85.71%)
Mutual labels:  base64
b2a
btoa and atob support for node.js or old browsers, with the Unicode Problems fixed
Stars: ✭ 21 (-92.11%)
Mutual labels:  base64
scure-base
Secure, audited & 0-deps implementation of bech32, base64, base32, base16 & base58
Stars: ✭ 27 (-89.85%)
Mutual labels:  base64

base64

Docs Build codecov unsafe forbidden

Made with CLion. Thanks to JetBrains for supporting open source!

It's base64. What more could anyone want?

This library's goals are to be correct and fast. It's thoroughly tested and widely used. It exposes functionality at multiple levels of abstraction so you can choose the level of convenience vs performance that you want, e.g. decode_config_slice decodes into an existing &mut [u8] and is pretty fast (2.6GiB/s for a 3 KiB input), whereas decode_config allocates a new Vec<u8> and returns it, which might be more convenient in some cases, but is slower (although still fast enough for almost any purpose) at 2.1 GiB/s.

Example

extern crate base64;

use base64::{encode, decode};

fn main() {
    let a = b"hello world";
    let b = "aGVsbG8gd29ybGQ=";

    assert_eq!(encode(a), b);
    assert_eq!(a, &decode(b).unwrap()[..]);
}

See the docs for all the details.

Rust version compatibility

The minimum required Rust version is 1.36.0.

Contributing

Contributions are very welcome. However, because this library is used widely, and in security-sensitive contexts, all PRs will be carefully scrutinized. Beyond that, this sort of low level library simply needs to be 100% correct. Nobody wants to chase bugs in encoding of any sort.

All this means that it takes me a fair amount of time to review each PR, so it might take quite a while to carve out the free time to give each PR the attention it deserves. I will get to everyone eventually!

Developing

Benchmarks are in benches/. Running them requires nightly rust, but rustup makes it easy:

rustup run nightly cargo bench

Decoding is aided by some pre-calculated tables, which are generated by:

cargo run --example make_tables > src/tables.rs.tmp && mv src/tables.rs.tmp src/tables.rs

no_std

This crate supports no_std. By default the crate targets std via the std feature. You can deactivate the default-features to target core instead. In that case you lose out on all the functionality revolving around std::io, std::error::Error and heap allocations. There is an additional alloc feature that you can activate to bring back the support for heap allocations.

Profiling

On Linux, you can use perf for profiling. Then compile the benchmarks with rustup nightly run cargo bench --no-run.

Run the benchmark binary with perf (shown here filtering to one particular benchmark, which will make the results easier to read). perf is only available to the root user on most systems as it fiddles with event counters in your CPU, so use sudo. We need to run the actual benchmark binary, hence the path into target. You can see the actual full path with rustup run nightly cargo bench -v; it will print out the commands it runs. If you use the exact path that bench outputs, make sure you get the one that's for the benchmarks, not the tests. You may also want to cargo clean so you have only one benchmarks- binary (they tend to accumulate).

sudo perf record target/release/deps/benchmarks-* --bench decode_10mib_reuse

Then analyze the results, again with perf:

sudo perf annotate -l

You'll see a bunch of interleaved rust source and assembly like this. The section with lib.rs:327 is telling us that 4.02% of samples saw the movzbl aka bit shift as the active instruction. However, this percentage is not as exact as it seems due to a phenomenon called skid. Basically, a consequence of how fancy modern CPUs are is that this sort of instruction profiling is inherently inaccurate, especially in branch-heavy code.

 lib.rs:322    0.70 :     10698:       mov    %rdi,%rax
    2.82 :        1069b:       shr    $0x38,%rax
         :                  if morsel == decode_tables::INVALID_VALUE {
         :                      bad_byte_index = input_index;
         :                      break;
         :                  };
         :                  accum = (morsel as u64) << 58;
 lib.rs:327    4.02 :     1069f:       movzbl (%r9,%rax,1),%r15d
         :              // fast loop of 8 bytes at a time
         :              while input_index < length_of_full_chunks {
         :                  let mut accum: u64;
         :
         :                  let input_chunk = BigEndian::read_u64(&input_bytes[input_index..(input_index + 8)]);
         :                  morsel = decode_table[(input_chunk >> 56) as usize];
 lib.rs:322    3.68 :     106a4:       cmp    $0xff,%r15
         :                  if morsel == decode_tables::INVALID_VALUE {
    0.00 :        106ab:       je     1090e <base64::decode_config_buf::hbf68a45fefa299c1+0x46e>

Fuzzing

This uses cargo-fuzz. See fuzz/fuzzers for the available fuzzing scripts. To run, use an invocation like these:

cargo +nightly fuzz run roundtrip
cargo +nightly fuzz run roundtrip_no_pad
cargo +nightly fuzz run roundtrip_random_config -- -max_len=10240
cargo +nightly fuzz run decode_random

License

This project is dual-licensed under MIT and Apache 2.0.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].