mirror of
https://github.com/vbatts/imgsrv.git
synced 2024-11-24 00:55:41 +00:00
38 lines
718 B
Go
38 lines
718 B
Go
package main
|
|
|
|
import (
|
|
"math/rand"
|
|
"crypto/md5"
|
|
"fmt"
|
|
"hash/adler32"
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
func Rand64() int64 {
|
|
return rand.Int63()
|
|
}
|
|
|
|
/* Convinience method for getting md5 sum of a string */
|
|
func GetMd5FromString(blob string) (sum []byte) {
|
|
h := md5.New()
|
|
defer h.Reset()
|
|
io.WriteString(h,blob)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
/* Convinience method for getting md5 sum of some bytes */
|
|
func GetMd5FromBytes(blob []byte) (sum []byte) {
|
|
h := md5.New()
|
|
defer h.Reset()
|
|
h.Write(blob)
|
|
return h.Sum(nil)
|
|
}
|
|
|
|
/* get a small, decently unique hash */
|
|
func GetSmallHash() (small_hash string) {
|
|
h := adler32.New()
|
|
io.WriteString(h, fmt.Sprintf("%d", time.Now().Unix()))
|
|
return fmt.Sprintf("%X", h.Sum(nil))
|
|
}
|
|
|