Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use "crypto/rand".Read #158

Merged
merged 1 commit into from Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/client.go
Expand Up @@ -194,7 +194,7 @@ func drainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error) {
// Do not use as a reliable way to get unique IDs, instead use for things like logging.
func shortID() string {
b := make([]byte, 6)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
if _, err := rand.Read(b); err != nil {
panic(err)
}
return base64.StdEncoding.EncodeToString(b)
Expand Down
3 changes: 1 addition & 2 deletions error.go
Expand Up @@ -33,7 +33,6 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"strings"
)

Expand Down Expand Up @@ -359,7 +358,7 @@ func asErrorResponse(err error) *ErrorResponse {
// are not catastrophic.
func newErrorID() string {
b := make([]byte, 6)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
if _, err := rand.Read(b); err != nil {
panic(err)
}
return base64.StdEncoding.EncodeToString(b)
Expand Down
3 changes: 1 addition & 2 deletions middleware/log_request.go
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/json"
"io"
"net"
"net/http"
"sort"
Expand Down Expand Up @@ -112,7 +111,7 @@ func LogRequest(verbose bool, sensitiveHeaders ...string) goa.Middleware {
// Do not use as a reliable way to get unique IDs, instead use for things like logging.
func shortID() string {
b := make([]byte, 6)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
if _, err := rand.Read(b); err != nil {
panic(err)
}
return base64.StdEncoding.EncodeToString(b)
Expand Down
3 changes: 1 addition & 2 deletions middleware/request_id.go
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"net/http"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -34,7 +33,7 @@ func init() {
var b64 string
replacer := strings.NewReplacer("+", "", "/", "")
for len(b64) < 10 {
if _, err := io.ReadFull(rand.Reader, buf[:]); err != nil {
if _, err := rand.Read(buf[:]); err != nil {
panic(err)
}
b64 = base64.StdEncoding.EncodeToString(buf[:])
Expand Down
5 changes: 2 additions & 3 deletions middleware/xray/middleware.go
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/rand"
"fmt"
"io"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -108,7 +107,7 @@ func New(service, daemon string) (goa.Middleware, error) {
// compatible with AWS X-Ray.
func NewID() string {
b := make([]byte, 8)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
if _, err := rand.Read(b); err != nil {
panic(err)
}
return fmt.Sprintf("%x", b)
Expand All @@ -118,7 +117,7 @@ func NewID() string {
// compatible with AWS X-Ray.
func NewTraceID() string {
b := make([]byte, 12)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
if _, err := rand.Read(b); err != nil {
panic(err)
}
return fmt.Sprintf("%d-%x-%s", 1, time.Now().Unix(), fmt.Sprintf("%x", b))
Expand Down