feat: initial commit
This commit is contained in:
22
internal/crypto/rand.go
Normal file
22
internal/crypto/rand.go
Normal file
@ -0,0 +1,22 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func RandomBytes(size int) ([]byte, error) {
|
||||
data := make([]byte, size)
|
||||
|
||||
read, err := rand.Read(data)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if read != size {
|
||||
return nil, errors.New("unexpected number of read bytes")
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
Reference in New Issue
Block a user