Skip to main content

z-base-32: human-oriented base-32 encoding

Project description

z-base-32

The z-base-32 is a human oriented base32 encoding.

API

The library exposes two functions with following signatures and error type:

pub fn encode(input: &[u8]) -> String;

pub fn decode(input: &str) -> Result<Vec<u8>, DecodeError>;

pub struct DecodeError;

Example

use zbase32::{encode, decode};

fn main() {
    assert_eq!(encode(b"foo"), "c3zs6".to_string());
    assert_eq!(Ok(b"foo"), decode("c3zs6".to_string()));
    assert_eq!(decode(&encode(b"foo")).unwrap(), b"foo")
}

Python

Building

This crate can be compiled with feature flag python in which case it produces python bindings. To build a Python wheels use maturin:

maturin build --cargo-extra-args="--features python"

API

def encode(input: bytes) -> str:

def decode(input: str) -> bytes:

class DecodeError(Exception):

Example

import zbase32

assert zbase32.encode(b'foo') == 'c3zs6'

assert zbase32.decode('c3zs6') == b'foo'


try:
    zbase32.decode('invalid@char')
except zbase32.DecodeError as e:
    print(e)

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z_base_32-0.1.0.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distributions

z_base_32-0.1.0-cp39-cp39-manylinux_2_24_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

z_base_32-0.1.0-cp38-cp38-manylinux_2_24_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

z_base_32-0.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

z_base_32-0.1.0-cp36-cp36m-manylinux_2_24_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page