mirror of
https://github.com/vbatts/imgsrv.git
synced 2025-07-29 18:30:30 +00:00
hash: docs and argument
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
b3f5e06c4d
commit
416e4e85ab
2 changed files with 10 additions and 9 deletions
13
hash/hash.go
13
hash/hash.go
|
@ -14,11 +14,12 @@ func init() {
|
|||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// Rand64 is an int64 random number
|
||||
func Rand64() int64 {
|
||||
return rand.Int63()
|
||||
}
|
||||
|
||||
/* Convinience method for getting md5 sum of a string */
|
||||
// GetMd5FromString is a convinience method for getting md5 sum of a string
|
||||
func GetMd5FromString(blob string) (sum []byte) {
|
||||
h := md5.New()
|
||||
defer h.Reset()
|
||||
|
@ -26,7 +27,7 @@ func GetMd5FromString(blob string) (sum []byte) {
|
|||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
/* Convinience method for getting md5 sum of some bytes */
|
||||
// GetMd5FromBytes is a convinience method for getting md5 sum of some bytes
|
||||
func GetMd5FromBytes(blob []byte) (sum []byte) {
|
||||
h := md5.New()
|
||||
defer h.Reset()
|
||||
|
@ -34,9 +35,9 @@ func GetMd5FromBytes(blob []byte) (sum []byte) {
|
|||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
/* get a small, decently unique hash */
|
||||
func GetSmallHash() (small_hash string) {
|
||||
// GetSmallHash get a small, decently unique hash
|
||||
func GetSmallHash(num uint) string {
|
||||
h := sha256.New()
|
||||
io.WriteString(h, fmt.Sprintf("%d%d", Rand64()))
|
||||
return strings.ToLower(fmt.Sprintf("%X", h.Sum(nil)[0:4]))
|
||||
io.WriteString(h, fmt.Sprintf("%d%d", Rand64(), Rand64()))
|
||||
return strings.ToLower(fmt.Sprintf("%X", h.Sum(nil)[0:num]))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue