Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Encrypted KV Store
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
Encrypted KV Store
Merge requests
!12
implemented and tested transactions
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
implemented and tested transactions
transaction
into
master
Overview
0
Commits
1
Pipelines
0
Changes
7
Merged
Benjamin Wenger
requested to merge
transaction
into
master
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
7
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
4d68d4fe
1 commit,
1 year ago
7 files
+
264
−
7
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
filestore.go
+
42
−
0
Options
@@ -199,6 +199,48 @@ func (f *Filestore) SetBytes(key string, data []byte) error {
return
nil
}
// Transaction implements [KeyValue.Transaction]
func
(
f
*
Filestore
)
Transaction
(
key
string
,
op
TransactionOperation
)
(
old
[]
byte
,
existed
bool
,
err
error
)
{
encryptedKey
:=
f
.
getKey
(
key
)
lck
:=
f
.
getLock
(
encryptedKey
)
lck
.
Lock
()
defer
lck
.
Unlock
()
//get the key
encryptedContents
,
err
:=
read
(
encryptedKey
)
// if an error is received which is not the file is not found, return it
hasfile
:=
true
if
err
!=
nil
{
if
!
Exists
(
err
)
{
hasfile
=
false
}
else
{
return
nil
,
false
,
err
}
}
var
decryptedContents
[]
byte
if
hasfile
{
decryptedContents
,
err
=
decrypt
(
encryptedContents
,
f
.
password
)
if
err
!=
nil
{
return
nil
,
true
,
err
}
}
data
,
err
:=
op
(
decryptedContents
,
hasfile
)
if
err
!=
nil
{
return
decryptedContents
,
hasfile
,
err
}
encryptedNewContents
:=
encrypt
(
data
,
f
.
password
,
f
.
csprng
)
err
=
write
(
encryptedKey
,
encryptedNewContents
)
if
err
!=
nil
{
return
decryptedContents
,
hasfile
,
errors
.
WithStack
(
err
)
}
return
decryptedContents
,
hasfile
,
err
}
func
(
f
*
Filestore
)
getKey
(
key
string
)
string
{
encryptedKey
:=
hashStringWithPassword
(
key
,
f
.
password
)
encryptedKeyStr
:=
hex
.
EncodeToString
(
encryptedKey
)
Loading