logtail: do not panic in PrivateID.PublicID (#4815)

It is not idiomatic for Go code to panic for situations that
can be normal. For example, if a server receives PrivateID
from a client, it is normal for the server to call
PrivateID.PublicID to validate that the PublicID matches.
However, doing so would panic prior to this change.

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
pull/4816/head
Joe Tsai 2 years ago committed by GitHub
parent 3a182d5dd6
commit 96f73b3894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,10 +80,6 @@ func (id PrivateID) String() string {
}
func (id PrivateID) Public() (pub PublicID) {
var emptyID PrivateID
if id == emptyID {
panic("invalid logtail.Public() on an empty private ID")
}
h := sha256.New()
h.Write(id[:])
if n := copy(pub[:], h.Sum(pub[:0])); n != len(pub) {

Loading…
Cancel
Save