6.4. kink/BIN_HASHER¶
6.4.1. bin_hasher型¶
bin_hasherは、概念的には、不変のタプル (Hash_algorithm, Accumulated_bin) である。hashメソッドにTail_binが与えられると、Hash_algorithmによる (Accumulated_bin + Tail_bin) のハッシュ値を計算する。
Accumulated_binそのものを戻すメソッドはない。したがって実装は、Accumulated_binそれ自体のかわりに、Accumulated_binから計算された、圧縮された状態を保持しても良い。
例
:BIN.require_from('kink/')
:BIN_HASHER.require_from('kink/')
:Md5 <- BIN_HASHER.for('MD5')
stdout.print_line(Md5.hash.repr)
# md5(∅)
# => (bin 0xd4 0x1d 0x8c 0xd9 0x8f 0x00 0xb2 0x04 0xe9 0x80 0x09 0x98 0xec 0xf8 0x42 0x7e)
stdout.print_line(Md5.hash(BIN.of(1 2 3)).repr)
# md5(1 2 3)
# => (bin 0x52 0x89 0xdf 0x73 0x7d 0xf5 0x73 0x26 0xfc 0xdd 0x22 0x59 0x7a 0xfb 0x1f 0xac)
:Md5_123 <- Md5 + BIN.of(1 2 3)
stdout.print_line(Md5_123.hash.repr)
# md5(1 2 3)
# => (bin 0x52 0x89 0xdf 0x73 0x7d 0xf5 0x73 0x26 0xfc 0xdd 0x22 0x59 0x7a 0xfb 0x1f 0xac)
stdout.print_line(Md5_123.hash(BIN.of(4 5 6)).repr)
# md5(1 2 3 4 5 6)
# => (bin 0x6a 0xc1 0xe5 0x6b 0xc7 0x8f 0x03 0x10 0x59 0xbe 0x7b 0xe8 0x54 0x52 0x2c 0x4c)
6.4.1.1. Hasher.hash(...[Tail_bin=BIN.of()])¶
hashは、 (Accumulated_bin + Tail_bin) のハッシュ値を計算して、binを戻す。
事前条件
Tail_binはbin値でなければならない。
6.4.1.2. Hasher + Bin¶
`+` 演算子、つまりop_addメソッドは、 (Hash_algorithm, Accumulated_bin + Bin) の新しいbin_hasher値を戻す。
事前条件
Binはbin値でなければならない。
6.4.2. BIN_HASHER.for(Hash_algorithm ...[$config={}])¶
forは、 (Hash_algorithm, BIN.of()) のbin_hasher値を作る。
コンフィグメソッド:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = 例外を投げる関数
bin_hasherが作られたら、forは、bin_hasherを引数として$successを末尾呼び出しする。
Hash_algorithmがサポートされていなければ、forは、引数なしで$errorを末尾呼び出しする。
事前条件
Hash_algorithmはstr値でなければならない。
$successはbin_hasherを取る関数でなければならない。
$errorはサンクでなければならない。
6.4.3. BIN_HASHER.is?(Val)¶
is?は、Valがbin_hasherであるかどうかを戻す。