@@ -7,8 +7,8 @@ package resty
77
88import (
99 "bytes"
10+ "crypto/md5"
1011 "crypto/rand"
11- "crypto/sha256"
1212 "encoding/binary"
1313 "encoding/hex"
1414 "errors"
@@ -371,7 +371,7 @@ func newGUID() string {
371371 // Timestamp, 4 bytes, big endian
372372 binary .BigEndian .PutUint32 (b [:], uint32 (time .Now ().Unix ()))
373373
374- // Machine, first 3 bytes of sha256.Sum256([]byte( hostname) )
374+ // Machine, first 3 bytes of md5( hostname)
375375 b [4 ], b [5 ], b [6 ] = machineID [0 ], machineID [1 ], machineID [2 ]
376376
377377 // Pid, 2 bytes, specs don't specify endianness, but we use big endian.
@@ -403,12 +403,13 @@ var osHostname = os.Hostname
403403// readMachineID generates and returns a machine id.
404404// If this function fails to get the hostname it will cause a runtime error.
405405func readMachineID () []byte {
406- const idSize = 3
407- id := make ([] byte , idSize )
406+ var sum [ 3 ] byte
407+ id := sum [:]
408408
409409 if hostname , err := osHostname (); err == nil {
410- hash := sha256 .Sum256 ([]byte (hostname ))
411- copy (id , hash [:idSize ])
410+ hw := md5 .New ()
411+ _ , _ = hw .Write ([]byte (hostname ))
412+ copy (id , hw .Sum (nil ))
412413 return id
413414 }
414415
0 commit comments