]> gitweb.factorcode.org Git - factor.git/blob - basis/checksums/common/common.factor
use radix literals
[factor.git] / basis / checksums / common / common.factor
1 ! Copyright (C) 2006, 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.bitwise strings io.binary namespaces
4 make grouping byte-arrays ;
5 IN: checksums.common
6
7 SYMBOL: bytes-read
8
9 : calculate-pad-length ( length -- length' )
10     [ 56 < 55 119 ? ] keep - ;
11
12 : calculate-pad-length-long ( length -- length' )
13     [ 120 < 119 247 ? ] keep - ;
14
15 : pad-last-block ( str big-endian? length -- str )
16     [
17         [ % ] 2dip 0x80 ,
18         [ 0x3f bitand calculate-pad-length <byte-array> % ]
19         [ 3 shift 8 rot [ >be ] [ >le ] if % ] bi
20     ] B{ } make 64 group ;
21
22 : update-old-new ( old new -- )
23     [ [ get ] bi@ w+ dup ] 2keep [ set ] bi@ ; inline