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