merge crypto-impure feature into feature crypto-full

This commit is contained in:
Skgland
2026-05-25 19:07:20 +02:00
committed by Bennet Bleßmann
parent 61ebcdb56e
commit bdba7ba0f5
2 changed files with 16 additions and 19 deletions

View File

@@ -23,7 +23,7 @@ default = ["all-simple-cross", "tls", "http"]
# currently does not include # currently does not include
# ffi due to libffi # ffi due to libffi
# tls, http due to openssl # tls, http due to openssl
# crypto-impure due to ring # crypto-full due to ring
all-pure = ["repl", "hostname"] all-pure = ["repl", "hostname"]
# enables all features that are simple to get working for cross-compliation # enables all features that are simple to get working for cross-compliation
# currently all but tls, http as those depend on openssl # currently all but tls, http as those depend on openssl
@@ -34,8 +34,7 @@ hostname = ["dep:hostname"]
tls = ["dep:native-tls"] tls = ["dep:native-tls"]
http = ["dep:warp", "dep:reqwest"] http = ["dep:warp", "dep:reqwest"]
# crypto function that require non pure-rust dependencies # crypto function that require non pure-rust dependencies
crypto-impure = ["dep:ring"] crypto-full = ["dep:ring"]
crypto-full = ["crypto-impure"]
[lints.clippy] [lints.clippy]
collapsible_match = "allow" collapsible_match = "allow"

View File

@@ -75,10 +75,8 @@ use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
use blake2::{Blake2b512, Blake2s256}; use blake2::{Blake2b512, Blake2s256};
#[cfg(feature = "crypto-full")] #[cfg(feature = "crypto-full")]
use ring::aead;
#[cfg(feature = "crypto-impure")]
use ring::{ use ring::{
digest, hkdf, hmac, pbkdf2, aead, digest, hkdf, hmac, pbkdf2,
rand::{SecureRandom, SystemRandom}, rand::{SecureRandom, SystemRandom},
}; };
@@ -7846,7 +7844,7 @@ impl Machine {
#[inline(always)] #[inline(always)]
pub(crate) fn crypto_random_byte(&mut self) { pub(crate) fn crypto_random_byte(&mut self) {
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
{ {
let arg = self.machine_st.registers[1]; let arg = self.machine_st.registers[1];
let mut bytes: [u8; 1] = [0]; let mut bytes: [u8; 1] = [0];
@@ -7866,7 +7864,7 @@ impl Machine {
self.machine_st.unify_fixnum(byte, arg); self.machine_st.unify_fixnum(byte, arg);
} }
#[cfg(not(feature = "crypto-impure"))] #[cfg(not(feature = "crypto-full"))]
{ {
let stub_gen = || functor_stub(atom!("crypto_random_byte"), 1); let stub_gen = || functor_stub(atom!("crypto_random_byte"), 1);
let err = self.machine_st.missing_feature_error(atom!("crypto")); let err = self.machine_st.missing_feature_error(atom!("crypto"));
@@ -8004,7 +8002,7 @@ impl Machine {
) )
} }
_ => { _ => {
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
{ {
let ints = digest::digest( let ints = digest::digest(
match algorithm { match algorithm {
@@ -8030,7 +8028,7 @@ impl Machine {
) )
) )
} }
#[cfg(not(feature = "crypto-impure"))] #[cfg(not(feature = "crypto-full"))]
{ {
let stub_gen = || functor_stub(atom!("crypto_data_hash"), 1); let stub_gen = || functor_stub(atom!("crypto_data_hash"), 1);
let err = self.machine_st.missing_feature_error(atom!("crypto")); let err = self.machine_st.missing_feature_error(atom!("crypto"));
@@ -8048,7 +8046,7 @@ impl Machine {
pub(crate) fn crypto_hmac(&mut self) { pub(crate) fn crypto_hmac(&mut self) {
let stub_gen = || functor_stub(atom!("crypto_data_hash"), 3); let stub_gen = || functor_stub(atom!("crypto_data_hash"), 3);
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
{ {
let encoding = cell_as_atom!(self.deref_register(2)); let encoding = cell_as_atom!(self.deref_register(2));
let data = self.string_encoding_bytes(self.machine_st.registers[1], encoding); let data = self.string_encoding_bytes(self.machine_st.registers[1], encoding);
@@ -8084,7 +8082,7 @@ impl Machine {
unify!(self.machine_st, self.machine_st.registers[4], ints_list); unify!(self.machine_st, self.machine_st.registers[4], ints_list);
} }
#[cfg(not(feature = "crypto-impure"))] #[cfg(not(feature = "crypto-full"))]
{ {
let err = self.machine_st.missing_feature_error(atom!("crypto")); let err = self.machine_st.missing_feature_error(atom!("crypto"));
let exception = self.machine_st.error_form(err, stub_gen()); let exception = self.machine_st.error_form(err, stub_gen());
@@ -8096,7 +8094,7 @@ impl Machine {
pub(crate) fn crypto_data_hkdf(&mut self) { pub(crate) fn crypto_data_hkdf(&mut self) {
let stub1_gen = || functor_stub(atom!("crypto_data_hkdf"), 4); let stub1_gen = || functor_stub(atom!("crypto_data_hkdf"), 4);
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
{ {
let encoding = cell_as_atom!(self.deref_register(2)); let encoding = cell_as_atom!(self.deref_register(2));
let data = self.string_encoding_bytes(self.machine_st.registers[1], encoding); let data = self.string_encoding_bytes(self.machine_st.registers[1], encoding);
@@ -8167,7 +8165,7 @@ impl Machine {
unify!(self.machine_st, self.machine_st.registers[7], ints_list); unify!(self.machine_st, self.machine_st.registers[7], ints_list);
} }
#[cfg(not(feature = "crypto-impure"))] #[cfg(not(feature = "crypto-full"))]
{ {
let err = self.machine_st.missing_feature_error(atom!("crypto")); let err = self.machine_st.missing_feature_error(atom!("crypto"));
let exception = self.machine_st.error_form(err, stub1_gen()); let exception = self.machine_st.error_form(err, stub1_gen());
@@ -8179,7 +8177,7 @@ impl Machine {
pub(crate) fn crypto_password_hash(&mut self) { pub(crate) fn crypto_password_hash(&mut self) {
let stub1_gen = || functor_stub(atom!("crypto_password_hash"), 3); let stub1_gen = || functor_stub(atom!("crypto_password_hash"), 3);
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
{ {
use std::num::NonZeroU32; use std::num::NonZeroU32;
let data = self let data = self
@@ -8235,7 +8233,7 @@ impl Machine {
unify!(self.machine_st, self.machine_st.registers[4], ints_list); unify!(self.machine_st, self.machine_st.registers[4], ints_list);
} }
#[cfg(not(feature = "crypto-impure"))] #[cfg(not(feature = "crypto-full"))]
{ {
let err = self.machine_st.missing_feature_error(atom!("crypto")); let err = self.machine_st.missing_feature_error(atom!("crypto"));
let exception = self.machine_st.error_form(err, stub1_gen()); let exception = self.machine_st.error_form(err, stub1_gen());
@@ -9602,7 +9600,7 @@ impl Machine {
} }
} }
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
fn rng() -> &'static dyn SecureRandom { fn rng() -> &'static dyn SecureRandom {
use std::ops::Deref; use std::ops::Deref;
@@ -9611,10 +9609,10 @@ fn rng() -> &'static dyn SecureRandom {
RANDOM.deref() RANDOM.deref()
} }
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
struct MyKey<T: core::fmt::Debug + PartialEq>(T); struct MyKey<T: core::fmt::Debug + PartialEq>(T);
#[cfg(feature = "crypto-impure")] #[cfg(feature = "crypto-full")]
impl hkdf::KeyType for MyKey<usize> { impl hkdf::KeyType for MyKey<usize> {
fn len(&self) -> usize { fn len(&self) -> usize {
self.0 self.0