upgrade deps; rewrite smtp session
This commit is contained in:
43
vendor/github.com/jhillyerd/enmime/internal/stringutil/rand_source.go
generated
vendored
Normal file
43
vendor/github.com/jhillyerd/enmime/internal/stringutil/rand_source.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package stringutil
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var globalRandSource rand.Source
|
||||
|
||||
func init() {
|
||||
globalRandSource = NewLockedSource(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
||||
// NewLockedSource creates a source of randomness using the given seed.
|
||||
func NewLockedSource(seed int64) rand.Source64 {
|
||||
return &lockedSource{
|
||||
s: rand.NewSource(seed).(rand.Source64),
|
||||
}
|
||||
}
|
||||
|
||||
type lockedSource struct {
|
||||
lock sync.Mutex
|
||||
s rand.Source64
|
||||
}
|
||||
|
||||
func (x *lockedSource) Int63() int64 {
|
||||
x.lock.Lock()
|
||||
defer x.lock.Unlock()
|
||||
return x.s.Int63()
|
||||
}
|
||||
|
||||
func (x *lockedSource) Uint64() uint64 {
|
||||
x.lock.Lock()
|
||||
defer x.lock.Unlock()
|
||||
return x.s.Uint64()
|
||||
}
|
||||
|
||||
func (x *lockedSource) Seed(seed int64) {
|
||||
x.lock.Lock()
|
||||
defer x.lock.Unlock()
|
||||
x.s.Seed(seed)
|
||||
}
|
||||
16
vendor/github.com/jhillyerd/enmime/internal/stringutil/uuid.go
generated
vendored
16
vendor/github.com/jhillyerd/enmime/internal/stringutil/uuid.go
generated
vendored
@@ -3,19 +3,15 @@ package stringutil
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var uuidRand = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
var uuidMutex = &sync.Mutex{}
|
||||
|
||||
// UUID generates a random UUID according to RFC 4122.
|
||||
func UUID() string {
|
||||
// UUID generates a random UUID according to RFC 4122, using optional rand if supplied
|
||||
func UUID(rs rand.Source) string {
|
||||
uuid := make([]byte, 16)
|
||||
uuidMutex.Lock()
|
||||
_, _ = uuidRand.Read(uuid)
|
||||
uuidMutex.Unlock()
|
||||
if rs == nil {
|
||||
rs = globalRandSource
|
||||
}
|
||||
_, _ = rand.New(rs).Read(uuid)
|
||||
// variant bits; see section 4.1.1
|
||||
uuid[8] = uuid[8]&^0xc0 | 0x80
|
||||
// version 4 (pseudo-random); see section 4.1.3
|
||||
|
||||
Reference in New Issue
Block a user