Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bech32m Support #50

Merged
merged 5 commits into from Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/rust.yml
@@ -0,0 +1,65 @@
on: [pull_request]

name: Continuous Integration

jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.29.0
- stable
- nightly
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --features strict

fmt:
name: Rustfmt
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

clippy:
name: Clippy
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bech32"
version = "0.7.3"
version = "0.8.0"
authors = ["Clark Moody"]
repository = "https://github.com/rust-bitcoin/rust-bech32"
description = "Encodes and decodes the Bech32 format"
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
@@ -0,0 +1 @@
msrv = "1.29.0"
5 changes: 3 additions & 2 deletions fuzz/fuzz_targets/decode_rnd.rs
Expand Up @@ -10,7 +10,7 @@ fn do_test(data: &[u8]) {
Err(_) => return,
};

assert_eq!(bech32::encode(&b32.0, b32.1).unwrap(), data_str);
assert_eq!(bech32::encode(&b32.0, b32.1, b32.2).unwrap(), data_str);
}

#[cfg(feature = "afl")]
Expand All @@ -23,7 +23,8 @@ fn main() {
}

#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[macro_use]
extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
Expand Down
17 changes: 13 additions & 4 deletions fuzz/fuzz_targets/encode_decode.rs
Expand Up @@ -13,18 +13,26 @@ fn do_test(data: &[u8]) {
return;
}

let hrp = String::from_utf8_lossy(&data[1..hrp_end]).to_lowercase().to_string();
let hrp = String::from_utf8_lossy(&data[1..hrp_end])
.to_lowercase()
.to_string();

let dp = data[hrp_end..]
.iter()
.map(|b| bech32::u5::try_from_u8(b % 32).unwrap())
.collect::<Vec<_>>();

if let Ok(data_str) = bech32::encode(&hrp, &dp).map(|b32| b32.to_string()) {
let variant = if data[0] > 0x0f {
bech32::Variant::Bech32m
} else {
bech32::Variant::Bech32
};

if let Ok(data_str) = bech32::encode(&hrp, &dp, variant).map(|b32| b32.to_string()) {
let decoded = bech32::decode(&data_str);
let b32 = decoded.expect("should be able to decode own encoding");

assert_eq!(bech32::encode(&b32.0, &b32.1).unwrap(), data_str);
assert_eq!(bech32::encode(&b32.0, &b32.1, b32.2).unwrap(), data_str);
}
}

Expand All @@ -38,7 +46,8 @@ fn main() {
}

#[cfg(feature = "honggfuzz")]
#[macro_use] extern crate honggfuzz;
#[macro_use]
extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
Expand Down