MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / UnixTimePrefixedRandomNonce

Function UnixTimePrefixedRandomNonce

driver/oss/singularity.go:17–24  ·  view source on GitHub ↗

UnixTimePrefixedRandomNonce takes an int for the nonce size and returns a byte slice of length size. A byte slice is created for the nonce and filled with random data from `crypto/rand`, then the first 4 bytes of the nonce are overwritten with LittleEndian encoding of `time.Now().Unix()` The purpose

(size int)

Source from the content-addressed store, hash-verified

15// The purpose of this function is to avoid an unlikely collision in randomly generating nonces
16// by prefixing the nonce with time series data.
17func UnixTimePrefixedRandomNonce(size int) []byte {
18 nonce := make([]byte, size)
19 rand.Read(nonce)
20 timeBytes := make([]byte, 8)
21 binary.LittleEndian.PutUint64(timeBytes, uint64(time.Now().Unix()))
22 copy(nonce, timeBytes[:4])
23 return nonce
24}
25
26func encrypt(data []byte, key []byte) []byte {
27 block, _ := aes.NewCipher(key)

Callers 1

encryptFunction · 0.70

Calls 1

ReadMethod · 0.45

Tested by

no test coverage detected