Skip to content
Snippets Groups Projects
Commit cb8b1c9b authored by Niamh Nikali's avatar Niamh Nikali
Browse files

Merge branch 'fix-burntstring' into 'dispatch'

Use random bytes instead of runes for burntString

See merge request !152
parents 862430c6 dd9e4bd4
No related branches found
No related tags found
No related merge requests found
......@@ -361,13 +361,9 @@ func clearCyclicInt(c *cyclic.Int) {
// FIXME Shouldn't we just be putting pseudorandom bytes in to obscure the mem?
func burntString(length int) string {
b := make([]byte, length)
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, length)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
rand.Read(b)
return string(b)
}
......@@ -239,3 +239,24 @@ func TestGetPrivKey(t *testing.T) {
t.Errorf("Private key is not returned correctly!")
}
}
func TestBruntString(t *testing.T) {
// Generate a new user and record the pointer to the nick
u := new(User)
u.Nick = "Mario"
preBurnPointer := &u.Nick
// Burn the string and record the pointer to the nick
u.Nick = burntString(len(u.Nick))
postBurnPointer := &u.Nick
// Check the nick is not the same as before
if u.Nick == "Mario" {
t.Errorf("String was not burnt")
}
// Check the pointer is the same (otherwise it wasn't overwritten)
if preBurnPointer != postBurnPointer {
t.Errorf("Pointer values are not the same")
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment