Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9665)

Unified Diff: common/logdog/types/streamsecret.go

Issue 1910923002: LogDog: Add project namespace to service endpoint. (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-coordinator-backend
Patch Set: Comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/api/logdog_coordinator/services/v1/util.go ('k') | server/internal/logdog/collector/collector.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/logdog/types/streamsecret.go
diff --git a/common/logdog/types/streamsecret.go b/common/logdog/types/streamsecret.go
index 0b2fad2b9606edcfc2fb80eba1c29f908d4d2774..74e0c28c8ccfb0c7e6facaf4916c6bcd7a7286fd 100644
--- a/common/logdog/types/streamsecret.go
+++ b/common/logdog/types/streamsecret.go
@@ -6,31 +6,43 @@ package types
import (
"crypto/rand"
- "errors"
+ "fmt"
)
const (
- // StreamSecretLength is the size, in bytes, of the stream secret.
+ // PrefixSecretLength is the size, in bytes, of the stream secret.
//
// This value was chosen such that it is:
// - Sufficiently large to avoid collisions.
// - Can be expressed as a Base64 string without ugly padding.
- StreamSecretLength = 36
+ PrefixSecretLength = 36
)
-// StreamSecret is the stream secret value. This is a Base64-encoded secret
+// PrefixSecret is the stream secret value. This is a Base64-encoded secret
// value.
-type StreamSecret []byte
+type PrefixSecret []byte
-// NewStreamSecret generates a new, default-length secret parameter.
-func NewStreamSecret() (StreamSecret, error) {
- buf := make([]byte, StreamSecretLength)
- count, err := rand.Read(buf)
- if err != nil {
+// NewPrefixSecret generates a new, default-length secret parameter.
+func NewPrefixSecret() (PrefixSecret, error) {
+ buf := make([]byte, PrefixSecretLength)
+ if _, err := rand.Read(buf); err != nil {
return nil, err
}
- if count != len(buf) {
- return nil, errors.New("streamsecret: Generated secret with invalid size")
+
+ value := PrefixSecret(buf)
+ if err := value.Validate(); err != nil {
+ panic(err)
+ }
+ return value, nil
+}
+
+// Validate confirms that this prefix secret is conformant.
+//
+// Note that this does not scan the byte contents of the secret for any
+// security-related parameters.
+func (s PrefixSecret) Validate() error {
+ if len(s) != PrefixSecretLength {
+ return fmt.Errorf("invalid prefix secret length (%d != %d)", len(s), PrefixSecretLength)
}
- return StreamSecret(buf), nil
+ return nil
}
« no previous file with comments | « common/api/logdog_coordinator/services/v1/util.go ('k') | server/internal/logdog/collector/collector.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698