mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2026-02-06 23:42:17 +00:00
Compare commits
2 Commits
seed-rand
...
fix-basic-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5664b433d | ||
|
|
fc6f897eaa |
@@ -26,9 +26,12 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
cryptoRand "crypto/rand"
|
||||
"crypto/tls"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"log"
|
||||
"math/rand"
|
||||
"mime"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
@@ -271,8 +274,9 @@ func UseLetsEncrypt(hosts []string) OptionFn {
|
||||
},
|
||||
}
|
||||
|
||||
srvr.tlsConfig = m.TLSConfig()
|
||||
srvr.tlsConfig.GetCertificate = m.GetCertificate
|
||||
srvr.tlsConfig = &tls.Config{
|
||||
GetCertificate: m.GetCertificate,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,6 +403,14 @@ func New(options ...OptionFn) (*Server, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
var seedBytes [8]byte
|
||||
if _, err := cryptoRand.Read(seedBytes[:]); err != nil {
|
||||
panic("cannot obtain cryptographically secure seed")
|
||||
}
|
||||
rand.Seed(int64(binary.LittleEndian.Uint64(seedBytes[:])))
|
||||
}
|
||||
|
||||
// Run starts Server
|
||||
func (s *Server) Run() {
|
||||
listening := false
|
||||
|
||||
@@ -25,22 +25,9 @@ THE SOFTWARE.
|
||||
package server
|
||||
|
||||
import (
|
||||
cryptoRand "crypto/rand"
|
||||
"encoding/binary"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
var seed *rand.Rand
|
||||
|
||||
func init() {
|
||||
var seedBytes [8]byte
|
||||
if _, err := cryptoRand.Read(seedBytes[:]); err != nil {
|
||||
panic("cannot obtain cryptographically secure seed")
|
||||
}
|
||||
|
||||
seed = rand.New(rand.NewSource(int64(binary.LittleEndian.Uint64(seedBytes[:]))))
|
||||
}
|
||||
|
||||
const (
|
||||
// SYMBOLS characters used for short-urls
|
||||
SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
@@ -50,7 +37,7 @@ const (
|
||||
func token(length int) string {
|
||||
result := ""
|
||||
for i := 0; i < length; i++ {
|
||||
x := seed.Intn(len(SYMBOLS) - 1)
|
||||
x := rand.Intn(len(SYMBOLS) - 1)
|
||||
result = string(SYMBOLS[x]) + result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user