title: HMAC-SHA1 in Rust
body: <p>I'm trying to apply HMAC-SHA1 in order to check some content but I'm unable to make it work.</p>
  
  <p>These are the tests I have:</p>
  
  <pre><code>#[cfg(test)]
  mod tests {
  
      use crypto::hmac::Hmac;
      use crypto::mac::Mac;
  
      use crypto::sha1::Sha1;
      use std::str::from_utf8;
  
      const BODY_CONTENT: &amp;'static str = r#"bodystring"#;
      const KEY: &amp;[u8] = b"secret_key";
      const COMPUTED_HMAC: &amp;'static str = "97049623b0e5d20bf6beb5313d80600e3d6abe56";
  
      #[test]
      fn test_hmac_sha1() {
          let mut mac= Hmac::new(Sha1::new(), KEY);
          mac.input(BODY_CONTENT.as_bytes());
          let result = mac.result();
          let code = result.code();
          assert_eq!(COMPUTED_HMAC.as_bytes(), code);
          assert_eq!(COMPUTED_HMAC, from_utf8(&amp;code).unwrap_or("failed"));
      }
  
      #[test]
      fn test_hmac_sha1_direct() {
          let hash = hmacsha1::hmac_sha1(KEY, BODY_CONTENT.as_bytes());
          assert_eq!(COMPUTED_HMAC.as_bytes(), hash);
          assert_eq!(COMPUTED_HMAC, from_utf8(&amp;hash).unwrap_or("failed"));
      }
  }
  </code></pre>
  
  <p>I've used this <a href="https://www.freeformatter.com/hmac-generator.html" rel="noreferrer">website</a> in order to get the <code>COMPUTED_HMAC</code> by using one string (<code>BODY_CONTENT</code>) and a secret key (<code>KEY</code>).</p>
  
  <p>As you can see, I'm trying to leverage both <a href="https://crates.io/crates/rust-crypto" rel="noreferrer">rust-crypto</a> and <a href="https://crates.io/crates/hmac-sha1" rel="noreferrer">hmac-sha1</a> crates and I obtain the same result with both of them. </p>
  
  <p>The thing is that this result doesn't match with what I get in the website (<code>97049623b0e5d20bf6beb5313d80600e3d6abe56</code>) and the tests fail. You may think that the website is wrong but that's not the case as I'm using it to validate some other hashes generated by Github (I'm working in a Github App) and it works.</p>
  
  <p>Then, obviously, I'm missing some step here but I'm unable to figure it out and I would really appreciate your help.</p>