File: manual_mh.rs

package info (click to toggle)
rust-multihash-codetable 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 180 kB
  • sloc: makefile: 2
file content (25 lines) | stat: -rw-r--r-- 783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use multihash_codetable::Code;
use multihash_derive::MultihashDigest;

/// prefix/multihash generating tool to aid when adding new tests
fn prefix_util() {
    use unsigned_varint::encode;
    // change these as needed
    let empty = Code::Sha2_256.wrap(&[]).unwrap().to_bytes();
    let hash = "7c8357577f51d4f0a8d393aa1aaafb28863d9421";

    // encode things
    let len = (hash.len() / 2) as u64; // always hex so len bytes is always half
    let mut buf = encode::u64_buffer();
    let len = encode::u64(len, &mut buf);

    let code_hex = hex::encode(&empty[..1]); // change if longer/shorter prefix
    let len_hex = hex::encode(len);
    println!("prefix hex: code: {code_hex}, len: {len_hex}");

    println!("{code_hex}{len_hex}{hash}");
}

fn main() {
    prefix_util()
}