NewHash returns a new UUID derived from the hash of space concatenated with data generated by h. The hash should be at least 16 byte in length. The first 16 bytes of the hash are used to form the UUID. The version of the UUID will be the lower 4 bits of version. NewHash is used to implement NewM
(h hash.Hash, space UUID, data []byte, version int)
| 31 | // UUID will be the lower 4 bits of version. NewHash is used to implement |
| 32 | // NewMD5 and NewSHA1. |
| 33 | func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID { |
| 34 | h.Reset() |
| 35 | h.Write(space[:]) //nolint:errcheck |
| 36 | h.Write(data) //nolint:errcheck |
| 37 | s := h.Sum(nil) |
| 38 | var uuid UUID |
| 39 | copy(uuid[:], s) |
| 40 | uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4) |
| 41 | uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant |
| 42 | return uuid |
| 43 | } |
| 44 | |
| 45 | // NewMD5 returns a new MD5 (Version 3) UUID based on the |
| 46 | // supplied name space and data. It is the same as calling: |