Update Picocrypt.go

This commit is contained in:
Evan Su 2021-05-28 16:47:41 -04:00 committed by GitHub
parent 008943fbba
commit d3fe04f32f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 51 additions and 10 deletions

View File

@ -37,10 +37,10 @@ import (
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
"golang.org/x/crypto/argon2" "golang.org/x/crypto/argon2"
g "github.com/AllenDang/giu" g "github.com/AllenDang/giu"
di "github.com/sqweek/dialog"
"golang.org/x/crypto/blake2b" "golang.org/x/crypto/blake2b"
"golang.org/x/crypto/blake2s" "golang.org/x/crypto/blake2s"
"github.com/atotto/clipboard" "github.com/atotto/clipboard"
di "github.com/OpenDiablo2/dialog"
"github.com/klauspost/reedsolomon" "github.com/klauspost/reedsolomon"
ig "github.com/AllenDang/imgui-go" ig "github.com/AllenDang/imgui-go"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
@ -108,7 +108,7 @@ var reedsolo bool
var split bool var split bool
var splitSize string var splitSize string
var fast bool var fast bool
var _fast bool
var kept = false var kept = false
@ -270,6 +270,11 @@ func startUI(){
// Start and cancel buttons // Start and cancel buttons
//g.Dummy(10,0), //g.Dummy(10,0),
g.Button("Start").Size(-1,20).OnClick(func(){ g.Button("Start").Size(-1,20).OnClick(func(){
if password!=cPassword{
_status = "Passwords don't match."
_status_color = color.RGBA{0xff,0x00,0x00,255}
return
}
if mode=="encrypt"{ if mode=="encrypt"{
outputFile = outputEntry+".pcv" outputFile = outputEntry+".pcv"
}else{ }else{
@ -658,6 +663,7 @@ func onDrop(names []string){
// Start encryption/decryption // Start encryption/decryption
func work(){ func work(){
debug.FreeOSMemory()
// Set some variables // Set some variables
working = true working = true
//headerBroken := false //headerBroken := false
@ -671,6 +677,7 @@ func work(){
var khash_hash []byte var khash_hash []byte
var _khash_hash []byte var _khash_hash []byte
var nonces []byte var nonces []byte
_fast = fast
// Set the output file based on mode // Set the output file based on mode
if mode=="encrypt"{ if mode=="encrypt"{
@ -869,6 +876,7 @@ func work(){
g.Update() g.Update()
status = "Deriving key..." status = "Deriving key..."
progress = 0
// Derive encryption/decryption key // Derive encryption/decryption key
var key []byte var key []byte
@ -893,6 +901,13 @@ func work(){
} }
fmt.Println("key",key) fmt.Println("key",key)
if !working{
_status = "Operation cancelled by user."
_status_color = color.RGBA{0xff,0xff,0xff,255}
fast = _fast
debug.FreeOSMemory()
return
}
if keyfile{ if keyfile{
kin,_ := os.Open(keyfilePath) kin,_ := os.Open(keyfilePath)
@ -954,6 +969,10 @@ func work(){
} }
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
key = nil key = nil
fast = _fast
if recombine{
os.Remove(inputFile)
}
debug.FreeOSMemory() debug.FreeOSMemory()
return return
} }
@ -1015,6 +1034,8 @@ func work(){
working = false working = false
_status = "The file is either corrupted or intentionally modified." _status = "The file is either corrupted or intentionally modified."
_status_color = color.RGBA{0xff,0x00,0x00,255} _status_color = color.RGBA{0xff,0x00,0x00,255}
fast = _fast
debug.FreeOSMemory()
return return
} }
} }
@ -1027,6 +1048,8 @@ func work(){
os.Remove(outputFile) os.Remove(outputFile)
_status = "Operation cancelled by user." _status = "Operation cancelled by user."
_status_color = color.RGBA{0xff,0xff,0xff,255} _status_color = color.RGBA{0xff,0xff,0xff,255}
fast = _fast
debug.FreeOSMemory()
return return
} }
//fmt.Println("Encrypt/decrypt loop") //fmt.Println("Encrypt/decrypt loop")
@ -1087,6 +1110,8 @@ func work(){
fin.Close() fin.Close()
fout.Close() fout.Close()
broken() broken()
fast = _fast
debug.FreeOSMemory()
return return
} }
} }
@ -1103,6 +1128,8 @@ func work(){
fin.Close() fin.Close()
fout.Close() fout.Close()
broken() broken()
fast = _fast
debug.FreeOSMemory()
return return
} }
} }
@ -1205,6 +1232,8 @@ func work(){
os.Remove(fmt.Sprintf("%s.%d",outputFile,i)) os.Remove(fmt.Sprintf("%s.%d",outputFile,i))
fmt.Println("outputFile",outputFile) fmt.Println("outputFile",outputFile)
os.Remove(outputFile) os.Remove(outputFile)
fast = _fast
debug.FreeOSMemory()
return return
} }
data = data[:read] data = data[:read]
@ -1292,7 +1321,7 @@ func shred(names []string,separate bool){
} }
for _,name := range(names){ for _,name := range(names){
shredding = name shredding = name
if runtime.GOOS=="linux"{ if runtime.GOOS=="linux"||runtime.GOOS=="darwin"{
stat,_ := os.Stat(name) stat,_ := os.Stat(name)
if stat.IsDir(){ if stat.IsDir(){
var coming []string var coming []string
@ -1309,7 +1338,12 @@ func shred(names []string,separate bool){
wg.Add(1) wg.Add(1)
go func(wg *sync.WaitGroup,id int,j string){ go func(wg *sync.WaitGroup,id int,j string){
defer wg.Done() defer wg.Done()
cmd := exec.Command("shred","-ufvz","-n","3",j) cmd := exec.Command("")
if runtime.GOOS=="linux"{
cmd = exec.Command("shred","-ufvz","-n","3",j)
}else{
cmd = exec.Command("rm","-rfP",j)
}
output,err := cmd.Output() output,err := cmd.Output()
fmt.Println(err) fmt.Println(err)
fmt.Println(output) fmt.Println(output)
@ -1331,7 +1365,12 @@ func shred(names []string,separate bool){
fmt.Println(coming) fmt.Println(coming)
for _,i := range(coming){ for _,i := range(coming){
go func(){ go func(){
cmd := exec.Command("shred","-ufvz","-n","3",i) cmd := exec.Command("")
if runtime.GOOS=="linux"{
cmd = exec.Command("shred","-ufvz","-n","3",i)
}else{
cmd = exec.Command("rm","-rfP",i)
}
output,err := cmd.Output() output,err := cmd.Output()
fmt.Println(err) fmt.Println(err)
fmt.Println(output) fmt.Println(output)
@ -1343,7 +1382,12 @@ func shred(names []string,separate bool){
} }
os.RemoveAll(name) os.RemoveAll(name)
}else{ }else{
cmd := exec.Command("shred","-ufvz","-n","3",name) cmd := exec.Command("")
if runtime.GOOS=="linux"{
cmd = exec.Command("shred","-ufvz","-n","3",name)
}else{
cmd = exec.Command("rm","-rfP",name)
}
cmd.Run() cmd.Run()
shredding = name+"/*" shredding = name+"/*"
shredDone++ shredDone++
@ -1383,10 +1427,6 @@ func shred(names []string,separate bool){
shredDone++ shredDone++
shredUpdate(separate) shredUpdate(separate)
} }
}else if runtime.GOOS=="darwin"{
if itemSelected==0{
exec.Command("rm -rfP \""+name+"\"")
}
} }
fmt.Println(name) fmt.Println(name)
g.Update() g.Update()
@ -1581,6 +1621,7 @@ func rsDecode(data []byte,encoder reedsolomon.Encoder,size int) []byte{
// Create the master window, set callbacks, and start the UI // Create the master window, set callbacks, and start the UI
func main(){ func main(){
di.Init()
if runtime.GOOS=="windows"{ if runtime.GOOS=="windows"{
exec.Command(filepath.Join(rootDir,"sdelete64.exe"),"/accepteula") exec.Command(filepath.Join(rootDir,"sdelete64.exe"),"/accepteula")
} }