Skip to content

Commit e16f18e

Browse files
authored
Merge pull request #16 from mrf345/testing
Fix header size in decrypt, and add file listing status update
2 parents 9a2c2f5 + 763e958 commit e16f18e

15 files changed

+172
-141
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ 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 **19.5** times faster than `gpgtar` and **10.1** times faster than `7zip`
53+
With the default settings the encryption should be about **18.5** times faster than `gpgtar` and **8.8** times faster than `7zip`
5454

5555
> [!NOTE]
5656
> 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/bench_and_plot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
safelock_cmd = "safelock-cli"
99
pwd = "123456789"
1010
rest = "60s"
11-
input_path = "~/Videos"
11+
input_path = "Videos"
1212
output_name = "test"
1313
output_dir = "safelock_dump"
1414
runs = 3

benchmark/decryption-time.webp

344 Bytes
Binary file not shown.

benchmark/decryption.json

+53-53
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"results": [
33
{
4-
"command": "echo \"123456789\" | safelock-cli decrypt test.sla safelock_dump --quiet",
5-
"mean": 2.5039628573266666,
6-
"stddev": 0.19691248469553527,
7-
"median": 2.55461392966,
8-
"user": 2.67419198,
9-
"system": 1.8112809399999998,
10-
"min": 2.28667279766,
11-
"max": 2.6706018446599997,
4+
"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,
1212
"times": [
13-
2.55461392966,
14-
2.6706018446599997,
15-
2.28667279766
13+
2.1494774636000002,
14+
2.1340488396,
15+
2.0315528936000002
1616
],
1717
"exit_codes": [
1818
0,
@@ -21,18 +21,18 @@
2121
]
2222
},
2323
{
24-
"command": "echo \"123456789\" | safelock-cli decrypt test_sha256.sla safelock_dump --quiet --sha256",
25-
"mean": 2.2569831443266666,
26-
"stddev": 0.30656745930113133,
27-
"median": 2.09402087566,
28-
"user": 2.3718176466666665,
29-
"system": 1.7837292733333332,
30-
"min": 2.0663134356599997,
31-
"max": 2.61061512166,
24+
"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,
3232
"times": [
33-
2.61061512166,
34-
2.0663134356599997,
35-
2.09402087566
33+
1.7543641936,
34+
2.0223575916,
35+
1.5966536246
3636
],
3737
"exit_codes": [
3838
0,
@@ -41,18 +41,18 @@
4141
]
4242
},
4343
{
44-
"command": "echo \"123456789\" | safelock-cli decrypt test_sha512.sla safelock_dump --quiet --sha512",
45-
"mean": 2.232521114326666,
46-
"stddev": 0.2060331833574435,
47-
"median": 2.2566013786599997,
48-
"user": 2.687645313333334,
49-
"system": 1.57915894,
50-
"min": 2.01550591466,
51-
"max": 2.4254560496599997,
44+
"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,
5252
"times": [
53-
2.2566013786599997,
54-
2.01550591466,
55-
2.4254560496599997
53+
2.2732154626,
54+
2.2400166546,
55+
2.2925006746000003
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": 19.035598546326668,
66-
"stddev": 1.0811270538832332,
67-
"median": 18.444795690659998,
68-
"user": 20.779736646666663,
69-
"system": 1.4327129399999998,
70-
"min": 18.37860840766,
71-
"max": 20.28339154066,
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,
7272
"times": [
73-
20.28339154066,
74-
18.37860840766,
75-
18.444795690659998
73+
20.0089831456,
74+
17.9281653906,
75+
17.9893611436
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": 6.697602776993334,
86-
"stddev": 0.675004732935611,
87-
"median": 6.57798586366,
88-
"user": 0.18233997999999998,
89-
"system": 1.4801756066666665,
90-
"min": 6.090402811660001,
91-
"max": 7.42441965566,
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,
9292
"times": [
93-
6.090402811660001,
94-
7.42441965566,
95-
6.57798586366
93+
6.0836583116,
94+
5.6110951406,
95+
5.5563355296
9696
],
9797
"exit_codes": [
9898
0,

benchmark/encryption-time.webp

312 Bytes
Binary file not shown.

benchmark/encryption.json

+55-55
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"results": [
33
{
4-
"command": "echo \"123456789\" | safelock-cli encrypt ~/Videos test.sla --quiet",
5-
"mean": 2.29175750412,
6-
"stddev": 0.38623578747101706,
7-
"median": 2.2869327251200002,
8-
"user": 3.4028373866666666,
9-
"system": 1.3263240666666667,
10-
"min": 1.90795670812,
11-
"max": 2.6803830791200003,
4+
"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,
1212
"times": [
13-
2.6803830791200003,
14-
2.2869327251200002,
15-
1.90795670812
13+
2.57482767894,
14+
2.03048120494,
15+
2.31758881894
1616
],
1717
"exit_codes": [
1818
0,
@@ -21,18 +21,18 @@
2121
]
2222
},
2323
{
24-
"command": "echo \"123456789\" | safelock-cli encrypt ~/Videos test_sha256.sla --quiet --sha256",
25-
"mean": 2.2089183144533338,
26-
"stddev": 0.07374517522754061,
27-
"median": 2.2169794741200004,
28-
"user": 3.6574827199999995,
29-
"system": 1.1812570666666664,
30-
"min": 2.1314737431200004,
31-
"max": 2.27830172612,
24+
"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,
3232
"times": [
33-
2.1314737431200004,
34-
2.27830172612,
35-
2.2169794741200004
33+
2.68289247394,
34+
2.23056378494,
35+
2.01408749594
3636
],
3737
"exit_codes": [
3838
0,
@@ -41,18 +41,18 @@
4141
]
4242
},
4343
{
44-
"command": "echo \"123456789\" | safelock-cli encrypt ~/Videos test_sha512.sla --quiet --sha512",
45-
"mean": 2.27866004312,
46-
"stddev": 0.40925382549422784,
47-
"median": 2.2914522451200003,
48-
"user": 3.7668190533333337,
49-
"system": 1.2321840666666664,
50-
"min": 1.8631600881200001,
51-
"max": 2.68136779612,
44+
"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,
5252
"times": [
53-
2.68136779612,
54-
1.8631600881200001,
55-
2.2914522451200003
53+
2.6520750169400005,
54+
2.27823183994,
55+
1.82332967894
5656
],
5757
"exit_codes": [
5858
0,
@@ -61,18 +61,18 @@
6161
]
6262
},
6363
{
64-
"command": "7z a -p123456789 -mx1 test.7z ~/Videos",
65-
"mean": 22.50626334912,
66-
"stddev": 0.7279365511833463,
67-
"median": 22.76205265512,
68-
"user": 164.54359772,
69-
"system": 1.2068337333333332,
70-
"min": 21.68495648412,
71-
"max": 23.07178090812,
64+
"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,
7272
"times": [
73-
21.68495648412,
74-
23.07178090812,
75-
22.76205265512
73+
20.00558599694,
74+
20.212478717939998,
75+
20.43993195494
7676
],
7777
"exit_codes": [
7878
0,
@@ -81,18 +81,18 @@
8181
]
8282
},
8383
{
84-
"command": "gpgtar -e -o test.gpg -c --yes --batch --gpg-args \"--passphrase 123456789\" Videos/",
85-
"mean": 43.15427112078667,
86-
"stddev": 1.5830989354414222,
87-
"median": 42.88658979412,
88-
"user": 33.29092905333333,
89-
"system": 9.646163066666666,
90-
"min": 41.72207785412,
91-
"max": 44.85414571412,
84+
"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,
9292
"times": [
93-
41.72207785412,
94-
42.88658979412,
95-
44.85414571412
93+
41.77658282994,
94+
42.49198231794,
95+
43.45635761594
9696
],
9797
"exit_codes": [
9898
0,

benchmark/file-size.webp

302 Bytes
Binary file not shown.

cmd/encrypt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var encryptCmd = &cobra.Command{
4848
sl.Quiet = beQuiet
4949
inputPath, outputPath := []string{args[0]}, args[1]
5050

51-
if outputFile, err = os.OpenFile(outputPath, os.O_RDWR|os.O_CREATE, 0776); err != nil {
51+
if outputFile, err = os.OpenFile(outputPath, os.O_RDWR|os.O_CREATE, 0755); err != nil {
5252
utils.PrintErrsAndExit((&slErrs.ErrInvalidOutputPath{
5353
Path: outputPath,
5454
Err: err,

safelock/decrypt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ func (sl *Safelock) decryptFiles(
100100
}
101101

102102
go sl.updateProgressStatus(ctx, "Decrypting", calc)
103-
defer slReader.cancel()
104103

105104
fileHandler := getExtractFileHandler(outputPath)
106105

107106
if err = sl.Archival.Extract(ctx, reader, nil, fileHandler); err != nil {
108107
return fmt.Errorf("cannot extract archive file > %w", err)
109108
}
110109

110+
slReader.cancel()
111111
return
112112
}
113113

safelock/encrypt.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ func (sl *Safelock) encryptFiles(
107107
slWriter *safelockWriter,
108108
calc *utils.PercentCalculator,
109109
) (err error) {
110-
sl.updateStatus("Listing and preparing files ", 5.0)
111-
112110
var files []archiver.File
113111
var filesMap = make(map[string]string, len(inputPaths))
112+
var cancelListingStatus = sl.updateListingStatus(ctx, 1.0, calc.Start)
114113

115114
for _, path := range inputPaths {
116115
filesMap[path] = ""
@@ -126,6 +125,7 @@ func (sl *Safelock) encryptFiles(
126125
calc.InputSize += int(file.Size())
127126
}
128127

128+
cancelListingStatus()
129129
sl.updateProgressStatus(ctx, "Encrypting", calc)
130130
}()
131131

@@ -138,6 +138,29 @@ func (sl *Safelock) encryptFiles(
138138
return
139139
}
140140

141+
func (sl *Safelock) updateListingStatus(ctx context.Context, start, end float64) (cancel context.CancelFunc) {
142+
ctx, cancel = context.WithCancel(ctx)
143+
144+
go func() {
145+
for {
146+
select {
147+
case <-ctx.Done():
148+
return
149+
default:
150+
if start >= end {
151+
return
152+
}
153+
154+
start += 1
155+
sl.updateStatus("Listing and preparing files", start)
156+
time.Sleep(time.Second / 2)
157+
}
158+
}
159+
}()
160+
161+
return
162+
}
163+
141164
func (sl *Safelock) updateProgressStatus(ctx context.Context, act string, calc *utils.PercentCalculator) {
142165
for {
143166
select {

0 commit comments

Comments
 (0)