std.crypto.sha1.Sha1
class pub Sha1
A SHA1 hasher.
Static methods
hash
Show source codeHide source code
fn pub static hash(bytes: ref ByteArray) -> Hash {
let hasher = new
hasher.write(bytes)
hasher.finish
}
fn pub static hash(bytes: ref ByteArray) -> Hash
Generates a hash for the given bytes.
Examples
import std.crypto.sha1 (Sha1)
Sha1.hash('hello')
new
Show source codeHide source code
fn pub static new -> Sha1 {
Sha1(
block: Block.new(BLOCK_SIZE),
words: Array.filled(with: 0, times: 80),
size: 0,
a: 0x67452301,
b: 0xEFCDAB89,
c: 0x98BADCFE,
d: 0x10325476,
e: 0xC3D2E1F0,
)
}
fn pub static new -> Sha1
Returns a new instance of the hasher.
Instance methods
finish
Show source codeHide source code
fn pub move finish -> Hash {
@block.add_padding(8, fn { compress })
@block.write_size_be(@size * 8, at: 56)
compress
let out = ByteArray.filled(with: 0, times: 20)
big.write_u32(@a, into: out, at: 0)
big.write_u32(@b, into: out, at: 4)
big.write_u32(@c, into: out, at: 8)
big.write_u32(@d, into: out, at: 12)
big.write_u32(@e, into: out, at: 16)
Hash.new(out)
}
fn pub move finish -> Hash
Generate a hash based on the current state.
write
Show source codeHide source code
fn pub mut write(bytes: ref ByteArray) {
@size += bytes.size
@block.write_bytes(bytes, fn { compress })
}
fn pub mut write(bytes: ref ByteArray)
Writes the bytes into the hasher.
This method is free to modify bytes
if needed, so no assumption should be
made about its contents after this method returns. If you're reusing the
same ByteArray
for multiple calls to write
, you should clear the
ByteArray
after each call.
Implemented traits
Hasher
impl Hasher for Sha1