@@ -223,6 +223,14 @@ mod digest_trait09 {
223223#[ cfg( feature = "traits010" ) ]
224224pub type WrappedHash = digest010:: core_api:: CoreWrapper < Hash > ;
225225
226+ #[ cfg( feature = "traits011" ) ]
227+ digest011:: buffer_fixed!(
228+ /// Wrapped `Hash` type for the `Digest` trait (digest 0.11).
229+ pub struct WrappedHash011 ( Hash ) ;
230+ oid: "1.3.14.3.2.26" ;
231+ impl : Debug Clone Default Reset HashMarker BlockSizeUser OutputSizeUser Update FixedOutput FixedOutputReset ;
232+ ) ;
233+
226234#[ cfg( feature = "traits010" ) ]
227235mod digest_trait010 {
228236 use core:: fmt;
@@ -292,6 +300,75 @@ mod digest_trait010 {
292300 }
293301}
294302
303+ #[ cfg( feature = "traits011" ) ]
304+ mod digest_trait011 {
305+ use core:: fmt;
306+
307+ use digest011:: {
308+ block_buffer:: Eager ,
309+ const_oid:: { AssociatedOid , ObjectIdentifier } ,
310+ consts:: { U20 , U64 } ,
311+ core_api:: {
312+ AlgorithmName , Block , BlockSizeUser , Buffer , BufferKindUser , FixedOutputCore ,
313+ OutputSizeUser , Reset , UpdateCore ,
314+ } ,
315+ HashMarker ,
316+ } ;
317+
318+ use super :: Hash ;
319+
320+ impl AssociatedOid for Hash {
321+ const OID : ObjectIdentifier = ObjectIdentifier :: new_unwrap ( "1.3.14.3.2.26" ) ;
322+ }
323+
324+ impl AlgorithmName for Hash {
325+ fn write_alg_name ( f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
326+ f. write_str ( "Sha1" )
327+ }
328+ }
329+
330+ impl HashMarker for Hash { }
331+
332+ impl BufferKindUser for Hash {
333+ type BufferKind = Eager ;
334+ }
335+
336+ impl BlockSizeUser for Hash {
337+ type BlockSize = U64 ;
338+ }
339+
340+ impl OutputSizeUser for Hash {
341+ type OutputSize = U20 ;
342+ }
343+
344+ impl UpdateCore for Hash {
345+ #[ inline]
346+ fn update_blocks ( & mut self , blocks : & [ Block < Self > ] ) {
347+ for block in blocks {
348+ self . _update ( block)
349+ }
350+ }
351+ }
352+
353+ impl FixedOutputCore for Hash {
354+ fn finalize_fixed_core (
355+ & mut self ,
356+ buffer : & mut Buffer < Self > ,
357+ out : & mut digest011:: Output < Self > ,
358+ ) {
359+ self . _update ( buffer. get_data ( ) ) ;
360+ let h = self . finalize ( ) ;
361+ out. copy_from_slice ( & h) ;
362+ }
363+ }
364+
365+ impl Reset for Hash {
366+ fn reset ( & mut self ) {
367+ * self = Self :: new ( )
368+ }
369+ }
370+ }
371+
295372#[ test]
296373fn main ( ) {
297374 let h = Hash :: hash ( b"" ) ;
@@ -355,3 +432,25 @@ fn main_traits() {
355432 ]
356433 ) ;
357434}
435+
436+ #[ cfg( feature = "traits011" ) ]
437+ #[ test]
438+ fn main_traits011 ( ) {
439+ use digest011:: Digest ;
440+ let mut h = WrappedHash011 :: new ( ) ;
441+ Digest :: update ( & mut h, b"" ) ;
442+ assert_eq ! (
443+ h. finalize( ) . as_slice( ) ,
444+ & [ 218 , 57 , 163 , 238 , 94 , 107 , 75 , 13 , 50 , 85 , 191 , 239 , 149 , 96 , 24 , 144 , 175 , 216 , 7 , 9 ]
445+ ) ;
446+
447+ let mut h = WrappedHash011 :: new ( ) ;
448+ Digest :: update ( & mut h, b"test" ) ;
449+ assert_eq ! (
450+ h. finalize( ) . as_slice( ) ,
451+ & [
452+ 169 , 74 , 143 , 229 , 204 , 177 , 155 , 166 , 28 , 76 , 8 , 115 , 211 , 145 , 233 , 135 , 152 , 47 ,
453+ 187 , 211
454+ ]
455+ ) ;
456+ }
0 commit comments