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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package types 5 package types
6 6
7 import ( 7 import (
8 "crypto/rand" 8 "crypto/rand"
9 » "errors" 9 » "fmt"
10 ) 10 )
11 11
12 const ( 12 const (
13 » // StreamSecretLength is the size, in bytes, of the stream secret. 13 » // PrefixSecretLength is the size, in bytes, of the stream secret.
14 // 14 //
15 // This value was chosen such that it is: 15 // This value was chosen such that it is:
16 // - Sufficiently large to avoid collisions. 16 // - Sufficiently large to avoid collisions.
17 // - Can be expressed as a Base64 string without ugly padding. 17 // - Can be expressed as a Base64 string without ugly padding.
18 » StreamSecretLength = 36 18 » PrefixSecretLength = 36
19 ) 19 )
20 20
21 // StreamSecret is the stream secret value. This is a Base64-encoded secret 21 // PrefixSecret is the stream secret value. This is a Base64-encoded secret
22 // value. 22 // value.
23 type StreamSecret []byte 23 type PrefixSecret []byte
24 24
25 // NewStreamSecret generates a new, default-length secret parameter. 25 // NewPrefixSecret generates a new, default-length secret parameter.
26 func NewStreamSecret() (StreamSecret, error) { 26 func NewPrefixSecret() (PrefixSecret, error) {
27 » buf := make([]byte, StreamSecretLength) 27 » buf := make([]byte, PrefixSecretLength)
28 » count, err := rand.Read(buf) 28 » if _, err := rand.Read(buf); err != nil {
29 » if err != nil {
30 return nil, err 29 return nil, err
31 } 30 }
32 » if count != len(buf) { 31
33 » » return nil, errors.New("streamsecret: Generated secret with inva lid size") 32 » value := PrefixSecret(buf)
33 » if err := value.Validate(); err != nil {
34 » » panic(err)
34 } 35 }
35 » return StreamSecret(buf), nil 36 » return value, nil
36 } 37 }
38
39 // Validate confirms that this prefix secret is conformant.
40 //
41 // Note that this does not scan the byte contents of the secret for any
42 // security-related parameters.
43 func (s PrefixSecret) Validate() error {
44 if len(s) != PrefixSecretLength {
45 return fmt.Errorf("invalid prefix secret length (%d != %d)", len (s), PrefixSecretLength)
46 }
47 return nil
48 }
OLDNEW
« 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