mirror of
https://github.com/Picocrypt/Picocrypt.git
synced 2025-05-12 13:48:31 +02:00
more error handling around keyfile generator
This commit is contained in:
parent
e72f687ae9
commit
89d461ce9c
1 changed files with 15 additions and 10 deletions
|
@ -587,22 +587,27 @@ func draw() {
|
||||||
}
|
}
|
||||||
return filepath.Dir(onlyFolders[0])
|
return filepath.Dir(onlyFolders[0])
|
||||||
}())
|
}())
|
||||||
f.SetInitFilename("Keyfile")
|
f.SetInitFilename("keyfile-" + strconv.Itoa(int(time.Now().Unix())) + ".bin")
|
||||||
file, err := f.Save()
|
file, err := f.Save()
|
||||||
if file == "" || err != nil {
|
if file == "" || err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fout, _ := os.Create(file)
|
fout, err := os.Create(file)
|
||||||
data := make([]byte, 32)
|
|
||||||
if _, err := rand.Read(data); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_, err = fout.Write(data)
|
|
||||||
fout.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
insufficientSpace(nil, nil)
|
return
|
||||||
os.Remove(file)
|
}
|
||||||
|
data := make([]byte, 32)
|
||||||
|
if n, err := rand.Read(data); err != nil || n != 32 {
|
||||||
|
panic(errors.New("fatal crypto/rand error"))
|
||||||
|
}
|
||||||
|
n, err := fout.Write(data)
|
||||||
|
if n != 32 {
|
||||||
|
fout.Close()
|
||||||
|
panic(errors.New("failed to write full keyfile"))
|
||||||
|
}
|
||||||
|
if err := fout.Close(); err != nil {
|
||||||
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
mainStatus = "Ready"
|
mainStatus = "Ready"
|
||||||
mainStatusColor = WHITE
|
mainStatusColor = WHITE
|
||||||
|
|
Loading…
Add table
Reference in a new issue