mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
crypto: add utility hexhash functions
This commit is contained in:
parent
bb9eec8696
commit
93716ee944
@ -49,7 +49,7 @@ fn (d mut Digest) reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new returns a new Digest (implementing hash.Hash) computing the MD5 checksum.
|
// new returns a new Digest (implementing hash.Hash) computing the MD5 checksum.
|
||||||
pub fn new() *Digest {
|
pub fn new() &Digest {
|
||||||
mut d := &Digest{}
|
mut d := &Digest{}
|
||||||
d.reset()
|
d.reset()
|
||||||
return d
|
return d
|
||||||
@ -141,3 +141,5 @@ fn block(dig mut Digest, p []byte) {
|
|||||||
pub fn (d &Digest) size() int { return Size }
|
pub fn (d &Digest) size() int { return Size }
|
||||||
|
|
||||||
pub fn (d &Digest) block_size() int { return BlockSize }
|
pub fn (d &Digest) block_size() int { return BlockSize }
|
||||||
|
|
||||||
|
pub fn hexhash(s string) string { return sum(s.bytes()).hex() }
|
||||||
|
@ -146,3 +146,5 @@ fn block(dig &Digest, p []byte) {
|
|||||||
pub fn (d &Digest) size() int { return Size }
|
pub fn (d &Digest) size() int { return Size }
|
||||||
|
|
||||||
pub fn (d &Digest) block_size() int { return BlockSize }
|
pub fn (d &Digest) block_size() int { return BlockSize }
|
||||||
|
|
||||||
|
pub fn hexhash(s string) string { return sum(s.bytes()).hex() }
|
||||||
|
@ -78,14 +78,14 @@ fn (d mut Digest) reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// new returns a new Digest (implementing hash.Hash) computing the SHA256 checksum.
|
// new returns a new Digest (implementing hash.Hash) computing the SHA256 checksum.
|
||||||
pub fn new() *Digest {
|
pub fn new() &Digest {
|
||||||
mut d := &Digest{}
|
mut d := &Digest{}
|
||||||
d.reset()
|
d.reset()
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
// new224 returns a new Digest (implementing hash.Hash) computing the SHA224 checksum.
|
// new224 returns a new Digest (implementing hash.Hash) computing the SHA224 checksum.
|
||||||
pub fn new224() *Digest {
|
pub fn new224() &Digest {
|
||||||
mut d := &Digest{}
|
mut d := &Digest{}
|
||||||
d.is224 = true
|
d.is224 = true
|
||||||
d.reset()
|
d.reset()
|
||||||
@ -212,3 +212,6 @@ pub fn (d &Digest) size() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn (d &Digest) block_size() int { return BlockSize }
|
pub fn (d &Digest) block_size() int { return BlockSize }
|
||||||
|
|
||||||
|
pub fn hexhash(s string) string { return sum256(s.bytes()).hex() }
|
||||||
|
pub fn hexhash_224(s string) string { return sum224(s.bytes()).hex() }
|
||||||
|
@ -120,29 +120,29 @@ fn (d mut Digest) reset() {
|
|||||||
d.len = u64(0)
|
d.len = u64(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _new(hash crypto.Hash) *Digest {
|
fn _new(hash crypto.Hash) &Digest {
|
||||||
mut d := &Digest{function: hash}
|
mut d := &Digest{function: hash}
|
||||||
d.reset()
|
d.reset()
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
// new returns a new Digest (implementing hash.Hash) computing the SHA-512 checksum.
|
// 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)
|
return _new(crypto.Hash.SHA512)
|
||||||
}
|
}
|
||||||
|
|
||||||
// new512_224 returns a new Digest (implementing hash.Hash) computing the SHA-512/224 checksum.
|
// 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)
|
return _new(crypto.Hash.SHA512_224)
|
||||||
}
|
}
|
||||||
|
|
||||||
// new512_256 returns a new Digest (implementing hash.Hash) computing the SHA-512/256 checksum.
|
// 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)
|
return _new(crypto.Hash.SHA512_256)
|
||||||
}
|
}
|
||||||
|
|
||||||
// new384 returns a new Digest (implementing hash.Hash) computing the SHA-384 checksum.
|
// new384 returns a new Digest (implementing hash.Hash) computing the SHA-384 checksum.
|
||||||
fn new384() *Digest {
|
fn new384() &Digest {
|
||||||
return _new(crypto.Hash.SHA384)
|
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 (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() }
|
||||||
|
Loading…
Reference in New Issue
Block a user