versa 1.9.0

Versa types and utilities for developing Versa client applications in Rust
Documentation
use base64::prelude::*;
use hmac::Mac;

#[cfg(feature = "client_sender")]
pub fn generate_token(body: bytes::Bytes, secret: String) -> String {
  let mut mac = hmac::Hmac::<sha1::Sha1>::new_from_slice(&secret.as_bytes()).unwrap();
  mac.update(body.as_ref());
  let code_bytes = mac.finalize().into_bytes();
  let encoded = BASE64_STANDARD.encode(&code_bytes.to_vec());
  encoded
}

#[cfg(feature = "client_receiver")]
pub fn verify_with_secret(body: bytes::Bytes, secret: String, token: &str) -> (bool, bytes::Bytes) {
  let mut mac = hmac::Hmac::<sha1::Sha1>::new_from_slice(&secret.as_bytes()).unwrap();
  mac.update(body.as_ref());
  let code_bytes = mac.finalize().into_bytes();
  let encoded = BASE64_STANDARD.encode(&code_bytes.to_vec());
  (encoded == token, body)
}