tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tests.rs (1082B)


      1 // Copyright 2023 Cryspen Sarl
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 pub fn simple<
     10    const OUTPUT_LEN: usize,
     11    IncrementalState,
     12    HashImplementation: super::arrayref::DigestIncremental<OUTPUT_LEN, IncrementalState = IncrementalState>
     13        + super::arrayref::Hash<OUTPUT_LEN>,
     14 >(
     15    // provide the state, since not all states currently implement `Default`
     16    state: IncrementalState,
     17 ) {
     18    let payload = &[1, 2, 3, 4, 5];
     19 
     20    // oneshot API
     21    let mut digest_oneshot = [0u8; OUTPUT_LEN];
     22    HashImplementation::hash(&mut digest_oneshot, payload).unwrap();
     23 
     24    // incremental API
     25    let mut digest_incremental = [0u8; OUTPUT_LEN];
     26    let mut hasher = super::Hasher::<OUTPUT_LEN, HashImplementation> { state };
     27    hasher.update(payload).unwrap();
     28    hasher.finish(&mut digest_incremental);
     29 
     30    // ensure same
     31    assert_eq!(digest_oneshot, digest_incremental);
     32 }