Add progress bars

This commit is contained in:
Evan Su 2024-04-25 18:07:42 -04:00 committed by GitHub
parent a91428b934
commit 77aea6a8e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 611 additions and 555 deletions

View file

@ -5,8 +5,13 @@ go 1.22.2
require (
github.com/HACKERALERT/infectious v0.0.0-20240424200929-b9ce72346a19
github.com/HACKERALERT/serpent v0.0.0-20210716182301-293b29869c66
github.com/schollz/progressbar/v3 v3.14.2
golang.org/x/crypto v0.22.0
golang.org/x/term v0.19.0
)
require golang.org/x/sys v0.19.1-0.20240416221847-9a28524796a5 // indirect
require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.19.1-0.20240416221847-9a28524796a5 // indirect
)

View file

@ -2,9 +2,28 @@ github.com/HACKERALERT/infectious v0.0.0-20240424200929-b9ce72346a19 h1:C5t561XX
github.com/HACKERALERT/infectious v0.0.0-20240424200929-b9ce72346a19/go.mod h1:bTnpEk9zNS1sVKg5TRvLkuSEGVqH0+LRfcMurPtcJvY=
github.com/HACKERALERT/serpent v0.0.0-20210716182301-293b29869c66 h1:YDpFq+y6mRcu97rn/rhYg8u8FdeO0wzTuLgM2gVkA+c=
github.com/HACKERALERT/serpent v0.0.0-20210716182301-293b29869c66/go.mod h1:d/+9q3sIxtIyOgHNgFGr3yGBKKVn5h3vL4hV1qlmoLs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/schollz/progressbar/v3 v3.14.2 h1:EducH6uNLIWsr560zSV1KrTeUb/wZGAHqyMFIEa99ks=
github.com/schollz/progressbar/v3 v3.14.2/go.mod h1:aQAZQnhF4JGFtRJiw/eobaXpsqpVQAftEQ+hLGXaRc4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.1-0.20240416221847-9a28524796a5 h1:0exPaeAtAlmNHCcRJc+hETS3/TcMV+yjoHhlp4+Ff3E=
golang.org/x/sys v0.19.1-0.20240416221847-9a28524796a5/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=

View file

@ -19,6 +19,7 @@ import (
"github.com/HACKERALERT/infectious"
"github.com/HACKERALERT/serpent"
"github.com/schollz/progressbar/v3"
"golang.org/x/crypto/argon2"
"golang.org/x/crypto/blake2b"
"golang.org/x/crypto/chacha20"
@ -103,6 +104,36 @@ func work() int {
}
}
var password, cpassword []byte
var err error
if mode == "encrypt" {
fmt.Print("Password: ")
password, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("Error reading password.")
return 1
}
fmt.Print(strings.Repeat("*", len(password)), " | Confirm: ")
cpassword, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("Error reading password.")
return 1
}
fmt.Println(strings.Repeat("*", len(cpassword)))
if !bytes.Equal(password, cpassword) {
fmt.Println("Passwords don't match.")
return 1
}
} else {
fmt.Print("Password: ")
password, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("Error reading password.")
return 1
}
fmt.Println(strings.Repeat("*", len(password)))
}
fin_, fout_ := "", ""
if mode == "decrypt" {
fin_ = flag.Arg(0)
@ -161,7 +192,7 @@ func work() int {
return 1
}
writer := zip.NewWriter(file)
for _, path := range files {
for i, path := range files {
stat, err := os.Stat(path)
if err != nil {
continue
@ -182,7 +213,7 @@ func work() int {
if err != nil {
continue
}
fin_, err := os.Open(path)
fin, err := os.Open(path)
if err != nil {
writer.Close()
file.Close()
@ -190,9 +221,18 @@ func work() int {
fmt.Println("Read access to input(s) denied.")
return 1
}
fmt.Println("Compressing:", abs)
_, err = io.Copy(entry, fin_)
fin_.Close()
bar := progressbar.NewOptions(
int(stat.Size()),
progressbar.OptionClearOnFinish(),
progressbar.OptionFullWidth(),
progressbar.OptionShowBytes(true),
progressbar.OptionUseIECUnits(true),
progressbar.OptionSetDescription(
fmt.Sprintf("Compressing [%d/%d]:", i+1, len(files)),
),
)
_, err = io.Copy(io.MultiWriter(entry, bar), fin)
fin.Close()
if err != nil {
writer.Close()
file.Close()
@ -209,37 +249,6 @@ func work() int {
}
}
var password []byte
var cpassword []byte
var err error
if mode == "encrypt" {
fmt.Print("Password: ")
password, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("\nError reading password.")
return 1
}
fmt.Print("\nConfirm: ")
cpassword, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("\nError reading password.")
return 1
}
if !bytes.Equal(password, cpassword) {
fmt.Println("\nPasswords don't match.")
return 1
}
fmt.Println()
} else {
fmt.Print("Password: ")
password, err = term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
fmt.Println("\nError reading password.")
return 1
}
fmt.Println()
}
var padded bool
var salt []byte // Argon2 salt, 16 bytes
var hkdfSalt []byte // HKDF-SHA3 salt, 32 bytes
@ -271,8 +280,10 @@ func work() int {
return 1
}
total := stat.Size()
if mode == "decrypt" {
total -= 789
}
if mode == "encrypt" {
fmt.Println("Generating volume header...")
errs := make([]error, 11)
salt = make([]byte, 16)
hkdfSalt = make([]byte, 32)
@ -313,7 +324,6 @@ func work() int {
}
}
} else {
fmt.Println("Reading volume header...")
errs := make([]error, 10)
version := make([]byte, 15)
fin.Read(version)
@ -420,6 +430,21 @@ func work() int {
s, _ := serpent.NewCipher(serpentKey)
serpent := cipher.NewCTR(s, serpentIV)
bar := progressbar.NewOptions(
int(total),
progressbar.OptionClearOnFinish(),
progressbar.OptionFullWidth(),
progressbar.OptionShowBytes(true),
progressbar.OptionUseIECUnits(true),
progressbar.OptionSetDescription(
(func() string {
if mode == "encrypt" {
return "Encrypting:"
}
return "Decrypting:"
})(),
),
)
for {
var src []byte
if mode == "decrypt" && *reedsolo {
@ -516,6 +541,12 @@ func work() int {
fmt.Println("Insufficient disk space.")
return 1
}
if mode == "decrypt" && *reedsolo {
done += MiB / 128 * 136
} else {
done += MiB
}
bar.Set(done)
if counter >= 60*GiB {
nonce = make([]byte, 24)
@ -527,6 +558,7 @@ func work() int {
counter = 0
}
}
bar.Set64(total)
if mode == "encrypt" {
fout.Seek(int64(309+0*3), 0)
@ -545,7 +577,7 @@ func work() int {
fin.Close()
fout.Close()
fmt.Println("Completed.")
fmt.Println("\nCompleted.")
return 0
}