Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Refactor `[u8]` -> `[u8; LEN]` where appropriate

Open
#102 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
cryptography

Research direction

Start at the core::traits::Hash definition shown in the issue, then inspect its implementations and the discussion in #49. Search the library for Vec and &[u8] values representing fixed-length data; done means the appropriate APIs use fixed-size arrays without losing implementation agnosticism, and the library still compiles.

Written by the indexing model from the issue text.

Description

bc-rust follows the general Rust paradigm of moving as many runtime error conditions as possible to instead be compile-time error conditions.

A prime candidate is core::traits:Hash:

pub trait Hash: Algorithm + Default {
    ...
    fn hash(self, data: &[u8]) -> Vec<u8>;
    fn hash_out(self, data: &[u8], output: &mut [u8]) -> usize;
    ...
}

Since, by definition, a hash function must produce a fixed-size output, this should really be:

pub trait Hash<const OUTPUT_LEN: usize>: Algorithm + Default {
    ...
    fn hash(self, data: &[u8]) -> [u8, OUTPUT_LEN];
    fn hash_out(self, data: &[u8], output: &mut [u8; OUTPUT_LEN]) -> usize;
    ...
}

since that resolves runtime ambiguity about the length of those arrays. Since this is part of the mathematical definition of a hash function, this should still be implementation-agnostic (ie any hash function should be able to implement this).

The task is to make the refactor above, and scan through the rest of the library for any other places where a value with a fixed length is currently being handled as an indefinite-length type (Vec or &[u8]).

This task is related to #49 , but not necessarily a subtask, since if we decide to keep the requirement on a global allocator, then the current Vec<u8> implementation does not technically need to change.

Dominant language
Rust
Stars
25
Forks
18
Avg merge
14d 10h
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bcgit/bc-rust

All issues in bcgit/bc-rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.