From dc145bfad70f58fbe6dff7fb791f4dce8b8c8766 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Sun, 21 Jun 2020 20:38:06 +0200 Subject: [PATCH] lib/protocol: Use sha256.Sum256 in NewDeviceID (#6775) This is shorter, skips two allocations, makes the function inlineable and is safer, since the compiler now check whether DeviceIDLength == sha256.Size. --- lib/protocol/deviceid.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/protocol/deviceid.go b/lib/protocol/deviceid.go index a721d44e2..c76b393fb 100644 --- a/lib/protocol/deviceid.go +++ b/lib/protocol/deviceid.go @@ -33,11 +33,7 @@ func repeatedDeviceID(v byte) (d DeviceID) { // NewDeviceID generates a new device ID from the raw bytes of a certificate func NewDeviceID(rawCert []byte) DeviceID { - var n DeviceID - hf := sha256.New() - hf.Write(rawCert) - hf.Sum(n[:0]) - return n + return DeviceID(sha256.Sum256(rawCert)) } func DeviceIDFromString(s string) (DeviceID, error) {