upgrade deps; rewrite smtp session

This commit is contained in:
Aine
2024-02-19 22:55:14 +02:00
parent 10213cc7d7
commit a01720da00
277 changed files with 106832 additions and 7641 deletions

View 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)
}

View File

@@ -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