From 712dd46883c058f5afa21a1183eca1cba388b042 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 8 Apr 2019 13:47:59 +0200 Subject: ffi-macros: Use crate sha2 instead of nettle. - We hash type names to create a compile-time-constant value for the runtime type checks in the wrapper types. Use sha2 instead of nettle, because the former is a pure-rust implementation, and doesn't require nettle at runtime. This makes building easier because we do not require nettle to be in the dynamic linker path at compile time. --- ffi-macros/Cargo.toml | 2 +- ffi-macros/src/lib.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'ffi-macros') diff --git a/ffi-macros/Cargo.toml b/ffi-macros/Cargo.toml index 38e658a6..02e1349a 100644 --- a/ffi-macros/Cargo.toml +++ b/ffi-macros/Cargo.toml @@ -19,9 +19,9 @@ maintenance = { status = "actively-developed" } [dependencies] lazy_static = "1.0.0" -nettle = "5.0" proc-macro2 = "0.4" quote = "0.6" +sha2 = "0.8" [dependencies.syn] version = "0.15" diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs index 4ebea637..112577c6 100644 --- a/ffi-macros/src/lib.rs +++ b/ffi-macros/src/lib.rs @@ -7,13 +7,12 @@ use std::io::Write; extern crate lazy_static; use lazy_static::lazy_static; -extern crate nettle; -use nettle::hash::Hash; extern crate syn; use syn::spanned::Spanned; extern crate quote; extern crate proc_macro; extern crate proc_macro2; +extern crate sha2; use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; @@ -255,13 +254,13 @@ fn derive_functions() -> &'static HashMap<&'static str, DeriveFn> /// Produces a deterministic hash of the given identifier. fn hash_ident(i: &syn::Ident) -> u64 { - let mut hash = ::nettle::hash::Sha256::default(); + use sha2::{Sha256, Digest}; + let mut hash = Sha256::new(); write!(hash, "{}", i).unwrap(); - let mut buf = [0; 8]; - hash.digest(&mut buf); + let result = hash.result(); - buf.iter().fold(0, |acc, b| (acc << 8) + (*b as u64)) + result[..8].iter().fold(0, |acc, b| (acc << 8) + (*b as u64)) } /// Derives type and conversion functions. -- cgit v1.2.3