refactor some weirdness in checksums.common

db4
Doug Coleman 2008-12-17 01:40:09 -06:00
parent 3da35fe529
commit be5a099379
1 changed files with 7 additions and 8 deletions

View File

@ -1,21 +1,20 @@
! Copyright (C) 2006, 2008 Doug Coleman. ! Copyright (C) 2006, 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.bitwise strings io.binary namespaces USING: kernel math math.bitwise strings io.binary namespaces
make grouping ; make grouping byte-arrays ;
IN: checksums.common IN: checksums.common
SYMBOL: bytes-read SYMBOL: bytes-read
: calculate-pad-length ( length -- pad-length ) : calculate-pad-length ( length -- length' )
dup 56 < 55 119 ? swap - ; [ 56 < 55 119 ? ] keep - ;
: pad-last-block ( str big-endian? length -- str ) : pad-last-block ( str big-endian? length -- str )
[ [
rot % [ % ] 2dip HEX: 80 ,
HEX: 80 , [ HEX: 3f bitand calculate-pad-length <byte-array> % ]
dup HEX: 3f bitand calculate-pad-length 0 <string> % [ 3 shift 8 rot [ >be ] [ >le ] if % ] bi
3 shift 8 rot [ >be ] [ >le ] if % ] B{ } make 64 group ;
] "" make 64 group ;
: update-old-new ( old new -- ) : update-old-new ( old new -- )
[ [ get ] bi@ w+ dup ] 2keep [ set ] bi@ ; inline [ [ get ] bi@ w+ dup ] 2keep [ set ] bi@ ; inline