mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 09:32:32 +08:00
6d6ba3aa7d
update algorithm consolidate MakeRandomString, RandomString & GenerateCrytoString into one function
33 lines
760 B
Go
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
|
|
}
|