@@ -109,69 +109,6 @@ macro_rules! engine_input_impl(
109109
110110
111111
112- macro_rules! define_slice_to_be {
113- ( $name: ident, $type: ty) => {
114- #[ inline]
115- pub fn $name( slice: & [ u8 ] ) -> $type {
116- assert_eq!( slice. len( ) , core:: mem:: size_of:: <$type>( ) ) ;
117- let mut res = 0 ;
118- for i in 0 ..:: core:: mem:: size_of:: <$type>( ) {
119- res |= ( slice[ i] as $type) << ( :: core:: mem:: size_of:: <$type>( ) - i - 1 ) * 8 ;
120- }
121- res
122- }
123- }
124- }
125- macro_rules! define_slice_to_le {
126- ( $name: ident, $type: ty) => {
127- #[ inline]
128- pub fn $name( slice: & [ u8 ] ) -> $type {
129- assert_eq!( slice. len( ) , core:: mem:: size_of:: <$type>( ) ) ;
130- let mut res = 0 ;
131- for i in 0 ..:: core:: mem:: size_of:: <$type>( ) {
132- res |= ( slice[ i] as $type) << i* 8 ;
133- }
134- res
135- }
136- }
137- }
138- macro_rules! define_be_to_array {
139- ( $name: ident, $type: ty, $byte_len: expr) => {
140- #[ inline]
141- pub fn $name( val: $type) -> [ u8 ; $byte_len] {
142- assert_eq!( :: core:: mem:: size_of:: <$type>( ) , $byte_len) ; // size_of isn't a constfn in 1.22
143- let mut res = [ 0 ; $byte_len] ;
144- for i in 0 ..$byte_len {
145- res[ i] = ( ( val >> ( $byte_len - i - 1 ) * 8 ) & 0xff ) as u8 ;
146- }
147- res
148- }
149- }
150- }
151- macro_rules! define_le_to_array {
152- ( $name: ident, $type: ty, $byte_len: expr) => {
153- #[ inline]
154- pub fn $name( val: $type) -> [ u8 ; $byte_len] {
155- assert_eq!( :: core:: mem:: size_of:: <$type>( ) , $byte_len) ; // size_of isn't a constfn in 1.22
156- let mut res = [ 0 ; $byte_len] ;
157- for i in 0 ..$byte_len {
158- res[ i] = ( ( val >> i* 8 ) & 0xff ) as u8 ;
159- }
160- res
161- }
162- }
163- }
164-
165- define_slice_to_be ! ( slice_to_u32_be, u32 ) ;
166- define_slice_to_be ! ( slice_to_u64_be, u64 ) ;
167- define_be_to_array ! ( u32_to_array_be, u32 , 4 ) ;
168- define_be_to_array ! ( u64_to_array_be, u64 , 8 ) ;
169-
170- define_slice_to_le ! ( slice_to_u32_le, u32 ) ;
171- define_slice_to_le ! ( slice_to_u64_le, u64 ) ;
172- define_le_to_array ! ( u32_to_array_le, u32 , 4 ) ;
173- define_le_to_array ! ( u64_to_array_le, u64 , 8 ) ;
174-
175112/// Creates a new newtype around a [`Hash`] type.
176113#[ macro_export]
177114macro_rules! hash_newtype {
@@ -302,28 +239,13 @@ pub mod json_hex_string {
302239mod test {
303240 use crate :: { Hash , sha256} ;
304241
305- use super :: * ;
306-
307242 #[ test]
308243 fn borrow_slice_impl_to_vec ( ) {
309244 // Test that the borrow_slice_impl macro gives to_vec.
310245 let hash = sha256:: Hash :: hash ( & [ 3 , 50 ] ) ;
311246 assert_eq ! ( hash. to_vec( ) . len( ) , sha256:: Hash :: LEN ) ;
312247 }
313248
314- #[ test]
315- fn endianness_test ( ) {
316- assert_eq ! ( slice_to_u32_be( & [ 0xde , 0xad , 0xbe , 0xef ] ) , 0xdeadbeef ) ;
317- assert_eq ! ( slice_to_u64_be( & [ 0x1b , 0xad , 0xca , 0xfe , 0xde , 0xad , 0xbe , 0xef ] ) , 0x1badcafedeadbeef ) ;
318- assert_eq ! ( u32_to_array_be( 0xdeadbeef ) , [ 0xde , 0xad , 0xbe , 0xef ] ) ;
319- assert_eq ! ( u64_to_array_be( 0x1badcafedeadbeef ) , [ 0x1b , 0xad , 0xca , 0xfe , 0xde , 0xad , 0xbe , 0xef ] ) ;
320-
321- assert_eq ! ( slice_to_u32_le( & [ 0xef , 0xbe , 0xad , 0xde ] ) , 0xdeadbeef ) ;
322- assert_eq ! ( slice_to_u64_le( & [ 0xef , 0xbe , 0xad , 0xde , 0xfe , 0xca , 0xad , 0x1b ] ) , 0x1badcafedeadbeef ) ;
323- assert_eq ! ( u32_to_array_le( 0xdeadbeef ) , [ 0xef , 0xbe , 0xad , 0xde ] ) ;
324- assert_eq ! ( u64_to_array_le( 0x1badcafedeadbeef ) , [ 0xef , 0xbe , 0xad , 0xde , 0xfe , 0xca , 0xad , 0x1b ] ) ;
325- }
326-
327249 hash_newtype ! ( TestHash , crate :: sha256d:: Hash , 32 , doc="Test hash." ) ;
328250
329251 #[ test]
0 commit comments