crypto: add utility hexhash functions

This commit is contained in:
Delyan Angelov 2019-09-02 20:22:19 +03:00 committed by Alexander Medvednikov
parent bb9eec8696
commit 93716ee944
4 changed files with 20 additions and 8 deletions

View file

@ -120,29 +120,29 @@ fn (d mut Digest) reset() {
d.len = u64(0)
}
fn _new(hash crypto.Hash) *Digest {
fn _new(hash crypto.Hash) &Digest {
mut d := &Digest{function: hash}
d.reset()
return d
}
// new returns a new Digest (implementing hash.Hash) computing the SHA-512 checksum.
pub fn new() *Digest {
pub fn new() &Digest {
return _new(crypto.Hash.SHA512)
}
// new512_224 returns a new Digest (implementing hash.Hash) computing the SHA-512/224 checksum.
fn new512_224() *Digest {
fn new512_224() &Digest {
return _new(crypto.Hash.SHA512_224)
}
// new512_256 returns a new Digest (implementing hash.Hash) computing the SHA-512/256 checksum.
fn new512_256() *Digest {
fn new512_256() &Digest {
return _new(crypto.Hash.SHA512_256)
}
// new384 returns a new Digest (implementing hash.Hash) computing the SHA-384 checksum.
fn new384() *Digest {
fn new384() &Digest {
return _new(crypto.Hash.SHA384)
}
@ -299,3 +299,8 @@ pub fn (d &Digest) size() int {
}
pub fn (d &Digest) block_size() int { return BlockSize }
pub fn hexhash(s string) string { return sum512(s.bytes()).hex() }
pub fn hexhash_384(s string) string { return sum384(s.bytes()).hex() }
pub fn hexhash_512_224(s string) string { return sum512_224(s.bytes()).hex() }
pub fn hexhash_512_256(s string) string { return sum512_256(s.bytes()).hex() }