aboutsummaryrefslogtreecommitdiff
path: root/backend/cache
diff options
context:
space:
mode:
authorRyan Mehri <[email protected]>2020-05-15 19:00:21 -0600
committerRyan Mehri <[email protected]>2020-05-15 19:00:21 -0600
commit4e03758e92887fe4251a73ce8125b93e8624b6a2 (patch)
tree7afe72a155fd9f6afd1bdded4a214b6fbba77fa0 /backend/cache
parentAdd encryption to content when password is specified (diff)
downloadctrl-v-4e03758e92887fe4251a73ce8125b93e8624b6a2.tar.xz
ctrl-v-4e03758e92887fe4251a73ce8125b93e8624b6a2.zip
Add comments and clean up encryption
Diffstat (limited to 'backend/cache')
-rw-r--r--backend/cache/cache.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index 6d5eb42..43e615a 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -17,7 +17,6 @@ var C *Cache
var PasteNotFound = errors.New("could not find a paste with that hash")
var UserUnauthorized = errors.New("paste is password protected")
-var EncryptionError = errors.New("could not encrypt the given content")
func init() {
C = &Cache{
@@ -52,17 +51,17 @@ func (c *Cache) Get(hash, userPassword string) (db.Paste, error) {
}
// if password matches, decrypt content
- key, _, err := security.DeriveKey([]byte(userPassword), p.Salt)
+ key, _, err := security.DeriveKey(userPassword, p.Salt)
if err != nil {
- return db.Paste{}, EncryptionError
+ return db.Paste{}, security.EncryptionError
}
- decryptedBytes, err := security.Decrypt(key, []byte(p.Content))
+ decryptedContent, err := security.Decrypt(key, p.Content)
if err != nil {
- return db.Paste{}, EncryptionError
+ return db.Paste{}, security.EncryptionError
}
- p.Content = string(decryptedBytes)
+ p.Content = decryptedContent
}
return p, nil