Skip to content

Commit 09741e5

Browse files
authored
Merge pull request #17 from mrf345/testing
Refactor pointors, and remove percent counter
2 parents e16f18e + c38cfdb commit 09741e5

15 files changed

+213
-251
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ You can find interactive examples of using it as a package to [encrypt](https://
5050

5151
### Performance
5252

53-
With the default settings the encryption should be about **18.5** times faster than `gpgtar` and **8.8** times faster than `7zip`
53+
- Encryption should be about **20.2** times faster than `gpgtar`, and the decryption **3.3** times.
54+
- Encryption should be about **9.1** times faster than `7zip`, and the decryption **9.5** times.
5455

5556
> [!NOTE]
5657
> You can reproduce the results by running [bench_and_plot.py](benchmark/bench_and_plot.py) (based on [Matplotlib](https://github.com/matplotlib/matplotlib) and [Hyperfine](https://github.com/sharkdp/hyperfine))

benchmark/decryption-time.webp

-312 Bytes
Binary file not shown.

benchmark/decryption.json

+50-50
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
"results": [
33
{
44
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli decrypt test.sla safelock_dump --quiet",
5-
"mean": 2.1050263989333335,
6-
"stddev": 0.06409584697239645,
7-
"median": 2.1340488396,
8-
"user": 2.565836426666667,
9-
"system": 1.86455084,
10-
"min": 2.0315528936000002,
11-
"max": 2.1494774636000002,
5+
"mean": 2.1295176539933336,
6+
"stddev": 0.03361454776096437,
7+
"median": 2.13093239266,
8+
"user": 2.5876522466666665,
9+
"system": 1.88427306,
10+
"min": 2.0952180726600003,
11+
"max": 2.16240249666,
1212
"times": [
13-
2.1494774636000002,
14-
2.1340488396,
15-
2.0315528936000002
13+
2.16240249666,
14+
2.13093239266,
15+
2.0952180726600003
1616
],
1717
"exit_codes": [
1818
0,
@@ -22,17 +22,17 @@
2222
},
2323
{
2424
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli decrypt test_sha256.sla safelock_dump --quiet --sha256",
25-
"mean": 1.7911251366,
26-
"stddev": 0.21521963683077622,
27-
"median": 1.7543641936,
28-
"user": 1.9575960933333334,
29-
"system": 1.67062184,
30-
"min": 1.5966536246,
31-
"max": 2.0223575916,
25+
"mean": 1.8789916449933333,
26+
"stddev": 0.17816416646803604,
27+
"median": 1.98184108566,
28+
"user": 2.0644982466666666,
29+
"system": 1.776121393333333,
30+
"min": 1.67326538666,
31+
"max": 1.9818684626599998,
3232
"times": [
33-
1.7543641936,
34-
2.0223575916,
35-
1.5966536246
33+
1.67326538666,
34+
1.98184108566,
35+
1.9818684626599998
3636
],
3737
"exit_codes": [
3838
0,
@@ -42,17 +42,17 @@
4242
},
4343
{
4444
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli decrypt test_sha512.sla safelock_dump --quiet --sha512",
45-
"mean": 2.268577597266667,
46-
"stddev": 0.026547606953880087,
47-
"median": 2.2732154626,
48-
"user": 2.8112754266666666,
49-
"system": 1.9018115066666663,
50-
"min": 2.2400166546,
51-
"max": 2.2925006746000003,
45+
"mean": 2.123450407993334,
46+
"stddev": 0.1763774710740607,
47+
"median": 2.1136010126600002,
48+
"user": 2.5975039133333335,
49+
"system": 1.7468127266666666,
50+
"min": 1.95220401166,
51+
"max": 2.3045461996600003,
5252
"times": [
53-
2.2732154626,
54-
2.2400166546,
55-
2.2925006746000003
53+
2.3045461996600003,
54+
2.1136010126600002,
55+
1.95220401166
5656
],
5757
"exit_codes": [
5858
0,
@@ -62,17 +62,17 @@
6262
},
6363
{
6464
"command": "7z e -y -p123456789 -mx1 test.7z -osafelock_dump",
65-
"mean": 18.642169893266665,
66-
"stddev": 1.1840904020013951,
67-
"median": 17.9893611436,
68-
"user": 20.570662093333336,
69-
"system": 1.4070678399999998,
70-
"min": 17.9281653906,
71-
"max": 20.0089831456,
65+
"mean": 17.944166026326666,
66+
"stddev": 0.03535223844853417,
67+
"median": 17.95858265166,
68+
"user": 19.665792913333334,
69+
"system": 1.4092493933333332,
70+
"min": 17.90388353266,
71+
"max": 17.97003189466,
7272
"times": [
73-
20.0089831456,
74-
17.9281653906,
75-
17.9893611436
73+
17.97003189466,
74+
17.90388353266,
75+
17.95858265166
7676
],
7777
"exit_codes": [
7878
0,
@@ -82,17 +82,17 @@
8282
},
8383
{
8484
"command": "gpgtar -d --yes --batch --gpg-args \"--passphrase 123456789\" test.gpg",
85-
"mean": 5.750362993933334,
86-
"stddev": 0.2899378904750308,
87-
"median": 5.6110951406,
88-
"user": 0.1864430933333333,
89-
"system": 1.3356181733333334,
90-
"min": 5.5563355296,
91-
"max": 6.0836583116,
85+
"mean": 6.240754918993335,
86+
"stddev": 0.18841334623779463,
87+
"median": 6.18021860166,
88+
"user": 0.17699391333333328,
89+
"system": 1.4514090599999998,
90+
"min": 6.09005041466,
91+
"max": 6.45199574066,
9292
"times": [
93-
6.0836583116,
94-
5.6110951406,
95-
5.5563355296
93+
6.45199574066,
94+
6.18021860166,
95+
6.09005041466
9696
],
9797
"exit_codes": [
9898
0,

benchmark/encryption-time.webp

-458 Bytes
Binary file not shown.

benchmark/encryption.json

+50-50
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
"results": [
33
{
44
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli encrypt Videos test.sla --quiet",
5-
"mean": 2.307632567606667,
6-
"stddev": 0.2723097797445358,
7-
"median": 2.31758881894,
8-
"user": 3.316105306666667,
9-
"system": 1.43377396,
10-
"min": 2.03048120494,
11-
"max": 2.57482767894,
5+
"mean": 2.2742533827266667,
6+
"stddev": 0.05119318397940522,
7+
"median": 2.28937216306,
8+
"user": 3.329233973333333,
9+
"system": 1.3630514999999999,
10+
"min": 2.21720349906,
11+
"max": 2.31618448606,
1212
"times": [
13-
2.57482767894,
14-
2.03048120494,
15-
2.31758881894
13+
2.21720349906,
14+
2.31618448606,
15+
2.28937216306
1616
],
1717
"exit_codes": [
1818
0,
@@ -22,17 +22,17 @@
2222
},
2323
{
2424
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli encrypt Videos test_sha256.sla --quiet --sha256",
25-
"mean": 2.3091812516066668,
26-
"stddev": 0.34126317439508236,
27-
"median": 2.23056378494,
28-
"user": 3.660151306666666,
29-
"system": 1.4299016266666664,
30-
"min": 2.01408749594,
31-
"max": 2.68289247394,
25+
"mean": 2.2029850927266668,
26+
"stddev": 0.2887786765513728,
27+
"median": 2.29156615106,
28+
"user": 3.45133264,
29+
"system": 1.3318238333333332,
30+
"min": 1.88029167006,
31+
"max": 2.43709745706,
3232
"times": [
33-
2.68289247394,
34-
2.23056378494,
35-
2.01408749594
33+
2.43709745706,
34+
1.88029167006,
35+
2.29156615106
3636
],
3737
"exit_codes": [
3838
0,
@@ -42,17 +42,17 @@
4242
},
4343
{
4444
"command": "echo \"123456789\" | ~/Projects/safelock-cli/safelock-cli encrypt Videos test_sha512.sla --quiet --sha512",
45-
"mean": 2.2512121786066666,
46-
"stddev": 0.4150328365179191,
47-
"median": 2.27823183994,
48-
"user": 3.4754706400000006,
49-
"system": 1.4172956266666665,
50-
"min": 1.82332967894,
51-
"max": 2.6520750169400005,
45+
"mean": 2.3804781427266666,
46+
"stddev": 0.2607000393652314,
47+
"median": 2.29337213106,
48+
"user": 3.7844909733333325,
49+
"system": 1.4182584999999996,
50+
"min": 2.17448372306,
51+
"max": 2.67357857406,
5252
"times": [
53-
2.6520750169400005,
54-
2.27823183994,
55-
1.82332967894
53+
2.67357857406,
54+
2.17448372306,
55+
2.29337213106
5656
],
5757
"exit_codes": [
5858
0,
@@ -62,17 +62,17 @@
6262
},
6363
{
6464
"command": "7z a -p123456789 -mx1 test.7z Videos",
65-
"mean": 20.219332223273334,
66-
"stddev": 0.21725406948835344,
67-
"median": 20.212478717939998,
68-
"user": 138.90269830666668,
69-
"system": 0.97966096,
70-
"min": 20.00558599694,
71-
"max": 20.43993195494,
65+
"mean": 20.227981493393333,
66+
"stddev": 0.47311415510031346,
67+
"median": 20.17403875506,
68+
"user": 137.52122964,
69+
"system": 0.9545411666666667,
70+
"min": 19.78415073906,
71+
"max": 20.72575498606,
7272
"times": [
73-
20.00558599694,
74-
20.212478717939998,
75-
20.43993195494
73+
20.72575498606,
74+
20.17403875506,
75+
19.78415073906
7676
],
7777
"exit_codes": [
7878
0,
@@ -82,17 +82,17 @@
8282
},
8383
{
8484
"command": "gpgtar -e -o test.gpg -c --yes --batch --gpg-args \"--passphrase 123456789\" Videos",
85-
"mean": 42.574974254606666,
86-
"stddev": 0.8429570446257044,
87-
"median": 42.49198231794,
88-
"user": 32.93103530666667,
89-
"system": 9.175310626666667,
90-
"min": 41.77658282994,
91-
"max": 43.45635761594,
85+
"mean": 44.902245365726664,
86+
"stddev": 1.3460233818310492,
87+
"median": 44.85683033906,
88+
"user": 33.18701430666666,
89+
"system": 9.421267166666667,
90+
"min": 43.57950423606,
91+
"max": 46.27040152206,
9292
"times": [
93-
41.77658282994,
94-
42.49198231794,
95-
43.45635761594
93+
46.27040152206,
94+
43.57950423606,
95+
44.85683033906
9696
],
9797
"exit_codes": [
9898
0,

benchmark/file-size.webp

-144 Bytes
Binary file not shown.

cmd/root.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var rootCmd = &cobra.Command{
1616
Use: "safelock-cli",
1717
Short: "Simple tool to encrypt/decrypt files with AES encryption",
1818
Long: "Simple command-line tool to encrypt and decrypt files with AES encryption",
19-
Version: "0.4.2",
19+
Version: "0.4.3",
2020
CompletionOptions: cobra.CompletionOptions{
2121
DisableDefaultCmd: true,
2222
},

safelock/core.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type asyncGcm struct {
2424
done chan bool
2525
}
2626

27-
func newAsyncGcm(pwd string, config EncryptionConfig, errs chan<- error) *asyncGcm {
28-
ag := &asyncGcm{
27+
func newAsyncGcm(pwd string, config EncryptionConfig, errs chan<- error) asyncGcm {
28+
ag := asyncGcm{
2929
pwd: pwd,
3030
config: config,
3131
errs: errs,

safelock/decrypt.go

+14-17
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
// and then outputs the content into `outputPath` which must be a valid path to an existing directory
1717
//
1818
// NOTE: `ctx` context is optional you can pass `nil` and the method will handle it
19-
func (sl *Safelock) Decrypt(ctx context.Context, input InputReader, outputPath, password string) (err error) {
19+
func (sl Safelock) Decrypt(ctx context.Context, input InputReader, outputPath, password string) (err error) {
2020
errs := make(chan error)
21-
signals, closeSignals := sl.getExitSignals()
21+
signals, closeSignals := utils.GetExitSignals()
2222

2323
if ctx == nil {
2424
ctx = context.Background()
@@ -33,27 +33,25 @@ func (sl *Safelock) Decrypt(ctx context.Context, input InputReader, outputPath,
3333
Trigger(StatusEnd.Str())
3434

3535
go func() {
36-
var calc *utils.PercentCalculator
37-
3836
if err = sl.validateDecryptionPaths(outputPath); err != nil {
3937
errs <- fmt.Errorf("invalid decryption input > %w", err)
4038
return
4139
}
4240

43-
if calc, err = utils.NewSeekerCalculator(input, 1.0); err != nil {
44-
errs <- fmt.Errorf("failed to read input paths > %w", err)
41+
ctx, cancel := context.WithCancel(ctx)
42+
reader := newReader(password, input, 1.0, cancel, sl.EncryptionConfig, errs)
43+
44+
if err = reader.setInputSize(); err != nil {
45+
errs <- fmt.Errorf("failed to read input > %w", err)
4546
return
4647
}
4748

48-
ctx, cancel := context.WithCancel(ctx)
49-
rw := newReader(password, input, cancel, calc, sl.EncryptionConfig, errs)
50-
51-
if err = rw.ReadHeader(); err != nil {
52-
errs <- fmt.Errorf("failed to read input file header > %w", err)
49+
if err = reader.ReadHeader(); err != nil {
50+
errs <- fmt.Errorf("failed to read input header > %w", err)
5351
return
5452
}
5553

56-
if err = sl.decryptFiles(ctx, outputPath, rw, calc); err != nil {
54+
if err = sl.decryptFiles(ctx, outputPath, reader); err != nil {
5755
errs <- fmt.Errorf("failed to extract archive file > %w", err)
5856
return
5957
}
@@ -87,19 +85,18 @@ func (sl *Safelock) validateDecryptionPaths(outputPath string) (err error) {
8785
return
8886
}
8987

90-
func (sl *Safelock) decryptFiles(
88+
func (sl Safelock) decryptFiles(
9189
ctx context.Context,
9290
outputPath string,
93-
slReader *safelockReader,
94-
calc *utils.PercentCalculator,
91+
slReader safelockReader,
9592
) (err error) {
9693
var reader io.ReadCloser
9794

98-
if reader, err = sl.Compression.OpenReader(slReader); err != nil {
95+
if reader, err = sl.Compression.OpenReader(&slReader); err != nil {
9996
return fmt.Errorf("cannot read archive file > %w", err)
10097
}
10198

102-
go sl.updateProgressStatus(ctx, "Decrypting", calc)
99+
go sl.updateProgressStatus(ctx, "Decrypting", slReader)
103100

104101
fileHandler := getExtractFileHandler(outputPath)
105102

0 commit comments

Comments
 (0)