mirror of
https://github.com/containers/podman.git
synced 2025-11-14 18:19:20 +08:00
Vendor in latest containers/storage
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
12
vendor/github.com/containers/storage/pkg/stringid/stringid.go
generated
vendored
12
vendor/github.com/containers/storage/pkg/stringid/stringid.go
generated
vendored
@@ -12,6 +12,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -20,6 +21,9 @@ const shortLen = 12
|
||||
var (
|
||||
validShortID = regexp.MustCompile("^[a-f0-9]{12}$")
|
||||
validHex = regexp.MustCompile(`^[a-f0-9]{64}$`)
|
||||
|
||||
rngLock sync.Mutex
|
||||
rng *rand.Rand // A RNG with seeding properties we control. It can only be accessed with randLock held.
|
||||
)
|
||||
|
||||
// IsShortID determines if an arbitrary string *looks like* a short ID.
|
||||
@@ -67,7 +71,9 @@ func GenerateRandomID() string {
|
||||
// secure sources of random.
|
||||
// It helps you to save entropy.
|
||||
func GenerateNonCryptoID() string {
|
||||
return generateID(readerFunc(rand.Read))
|
||||
rngLock.Lock()
|
||||
defer rngLock.Unlock()
|
||||
return generateID(readerFunc(rng.Read))
|
||||
}
|
||||
|
||||
// ValidateID checks whether an ID string is a valid image ID.
|
||||
@@ -79,7 +85,7 @@ func ValidateID(id string) error {
|
||||
}
|
||||
|
||||
func init() {
|
||||
// safely set the seed globally so we generate random ids. Tries to use a
|
||||
// Initialize a private RNG so we generate random ids. Tries to use a
|
||||
// crypto seed before falling back to time.
|
||||
var seed int64
|
||||
if cryptoseed, err := cryptorand.Int(cryptorand.Reader, big.NewInt(math.MaxInt64)); err != nil {
|
||||
@@ -89,7 +95,7 @@ func init() {
|
||||
seed = cryptoseed.Int64()
|
||||
}
|
||||
|
||||
rand.Seed(seed)
|
||||
rng = rand.New(rand.NewSource(seed))
|
||||
}
|
||||
|
||||
type readerFunc func(p []byte) (int, error)
|
||||
|
||||
Reference in New Issue
Block a user