/
encryption_access.go
43 lines (36 loc) · 1.35 KB
/
encryption_access.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package pb
import (
"encoding/base64"
"encoding/json"
"storj.io/common/encryption"
"storj.io/common/storj"
)
type encryptionAccessStoreEntryMarshal struct {
Bucket string `json:"bucket,omitempty"`
UnencryptedPath string `json:"unencrypted_path,omitempty"`
EncryptedPath string `json:"encrypted_path,omitempty"`
Key string `json:"key,omitempty"`
PathCipher CipherSuite `json:"path_cipher,omitempty"`
EncryptionParameters *EncryptionParameters `json:"encryption_parameters,omitempty"`
}
// MarshalJSON implements the json.Marshaler interface.
func (se *EncryptionAccess_StoreEntry) MarshalJSON() ([]byte, error) {
key, err := storj.NewKey([]byte{})
if err != nil {
return nil, err
}
path, err := encryption.DecryptPathRaw(string(se.EncryptedPath), storj.EncNullBase64URL, key)
if err != nil {
return nil, err
}
return json.Marshal(encryptionAccessStoreEntryMarshal{
Bucket: string(se.Bucket),
UnencryptedPath: string(se.UnencryptedPath),
EncryptedPath: path,
Key: base64.URLEncoding.EncodeToString(se.Key),
PathCipher: se.PathCipher,
EncryptionParameters: se.EncryptionParameters,
})
}