netmaker/netclient/ncutils/netclientutils.go
Matthew R Kasun 6d6ba3aa7d random string
update algorithm
consolidate MakeRandomString, RandomString & GenerateCrytoString into
one function
2023-05-02 13:28:00 -04:00

33 lines
760 B
Go

package ncutils
import (
"bytes"
"encoding/gob"
)
// DEFAULT_GC_PERCENT - garbage collection percent
const DEFAULT_GC_PERCENT = 10
// == OS PATH FUNCTIONS ==
// ConvertKeyToBytes - util to convert a key to bytes to use elsewhere
func ConvertKeyToBytes(key *[32]byte) ([]byte, error) {
var buffer bytes.Buffer
var enc = gob.NewEncoder(&buffer)
if err := enc.Encode(key); err != nil {
return nil, err
}
return buffer.Bytes(), nil
}
// ConvertBytesToKey - util to convert bytes to a key to use elsewhere
func ConvertBytesToKey(data []byte) (*[32]byte, error) {
var buffer = bytes.NewBuffer(data)
var dec = gob.NewDecoder(buffer)
var result = new([32]byte)
var err = dec.Decode(result)
if err != nil {
return nil, err
}
return result, err
}