Deprecate `from_slice()` in sha256.rs

Support for Rust arrays is now much better so slice-accepting
methods that require a fixed length can be replaced with a method that
accepts an array.

`from_slice()` has been deprecated. A `from_byte_array()` function
already exists to be used instead.
This commit is contained in:
Jamil Lambert, PhD 2024-09-05 16:13:29 +01:00
parent 089043546f
commit a20d0bc4eb
No known key found for this signature in database
GPG Key ID: 54DC29234AB5D2C0
1 changed files with 2 additions and 1 deletions

View File

@ -71,13 +71,14 @@ where
pub fn from_engine(e: HashEngine) -> Hash<T> { from_engine(e) } pub fn from_engine(e: HashEngine) -> Hash<T> { from_engine(e) }
/// Copies a byte slice into a hash object. /// Copies a byte slice into a hash object.
#[deprecated(since = "TBD", note = "Use `from_byte_array` instead.")]
pub fn from_slice(sl: &[u8]) -> Result<Hash<T>, FromSliceError> { pub fn from_slice(sl: &[u8]) -> Result<Hash<T>, FromSliceError> {
if sl.len() != 32 { if sl.len() != 32 {
Err(FromSliceError { expected: 32, got: sl.len() }) Err(FromSliceError { expected: 32, got: sl.len() })
} else { } else {
let mut ret = [0; 32]; let mut ret = [0; 32];
ret.copy_from_slice(sl); ret.copy_from_slice(sl);
Ok(Self::internal_new(ret)) Ok(Self::from_byte_array(ret))
} }
} }