@@ -80,7 +80,33 @@ pub trait FixedOutput {
80
80
type OutputSize : ArrayLength < u8 > ;
81
81
82
82
/// Retrieve result and consume hasher instance.
83
- fn finalize_fixed ( self ) -> GenericArray < u8 , Self :: OutputSize > ;
83
+ #[ inline]
84
+ fn finalize_fixed ( mut self ) -> GenericArray < u8 , Self :: OutputSize >
85
+ where
86
+ Self : Sized ,
87
+ {
88
+ self . finalize_fixed_reset ( )
89
+ }
90
+
91
+ /// Retrieve result and reset hasher instance.
92
+ #[ inline]
93
+ fn finalize_fixed_reset ( & mut self ) -> GenericArray < u8 , Self :: OutputSize > {
94
+ let mut buf = Default :: default ( ) ;
95
+ self . finalize_fixed_into_reset ( & mut buf) ;
96
+ buf
97
+ }
98
+
99
+ /// Retrieve result into provided buffer and consume hasher instance.
100
+ #[ inline]
101
+ fn finalize_fixed_into ( mut self , out : & mut GenericArray < u8 , Self :: OutputSize > )
102
+ where
103
+ Self : Sized ,
104
+ {
105
+ self . finalize_fixed_into_reset ( out) ;
106
+ }
107
+
108
+ /// Retrieve result and provided buffer and consume hasher instance.
109
+ fn finalize_fixed_into_reset ( & mut self , out : & mut GenericArray < u8 , Self :: OutputSize > ) ;
84
110
}
85
111
86
112
/// Trait for returning digest result with the variable size
@@ -99,7 +125,16 @@ pub trait VariableOutput: core::marker::Sized {
99
125
///
100
126
/// Closure is guaranteed to be called, length of the buffer passed to it
101
127
/// will be equal to `output_size`.
102
- fn finalize_variable < F : FnOnce ( & [ u8 ] ) > ( self , f : F ) ;
128
+ #[ inline]
129
+ fn finalize_variable ( mut self , f : impl FnOnce ( & [ u8 ] ) ) {
130
+ self . finalize_variable_reset ( f) ;
131
+ }
132
+
133
+ /// Retrieve result via closure and reset hasher.
134
+ ///
135
+ /// Closure is guaranteed to be called, length of the buffer passed to it
136
+ /// will be equal to `output_size`.
137
+ fn finalize_variable_reset ( & mut self , f : impl FnOnce ( & [ u8 ] ) ) ;
103
138
104
139
/// Retrieve result into vector and consume hasher.
105
140
#[ cfg( feature = "alloc" ) ]
@@ -135,7 +170,13 @@ pub trait ExtendableOutput: core::marker::Sized {
135
170
type Reader : XofReader ;
136
171
137
172
/// Retrieve XOF reader and consume hasher instance.
138
- fn finalize_xof ( self ) -> Self :: Reader ;
173
+ #[ inline]
174
+ fn finalize_xof ( mut self ) -> Self :: Reader {
175
+ self . finalize_xof_reset ( )
176
+ }
177
+
178
+ /// Retrieve XOF reader and reset hasher instance.
179
+ fn finalize_xof_reset ( & mut self ) -> Self :: Reader ;
139
180
140
181
/// Retrieve result into vector of specified length.
141
182
#[ cfg( feature = "alloc" ) ]
@@ -147,12 +188,6 @@ pub trait ExtendableOutput: core::marker::Sized {
147
188
}
148
189
}
149
190
150
- /// Trait for resetting hash instances
151
- pub trait Reset {
152
- /// Reset hasher instance to its initial state and return current state.
153
- fn reset ( & mut self ) ;
154
- }
155
-
156
191
#[ macro_export]
157
192
/// Implements `std::io::Write` trait for implementer of [`Update`]
158
193
macro_rules! impl_write {
0 commit comments