From db0c023fd0d756912c3f575c6ac65e99fda573cc Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Mon, 2 Oct 2017 14:26:26 +0200 Subject: Add filter storage method Also remove de/encryption in cloud storage, can be provided with a filter storage --- storage/memory/memory.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'storage/memory') diff --git a/storage/memory/memory.go b/storage/memory/memory.go index 456049b..e73c51a 100644 --- a/storage/memory/memory.go +++ b/storage/memory/memory.go @@ -22,12 +22,18 @@ func MemoryStorageFromConfig(conf config.Config, name string) (storage.Storage, return NewMemoryStorage(), nil } +func copyBytes(b []byte) []byte { + c := make([]byte, len(b)) + copy(c, b) + return c +} + func (ms MemoryStorage) Get(id objects.ObjectId) ([]byte, error) { b, ok := ms.objects[id.String()] if !ok { return nil, storage.ObjectNotFound } - return b, nil + return copyBytes(b), nil } func (ms MemoryStorage) Has(id objects.ObjectId) (bool, error) { @@ -36,7 +42,7 @@ func (ms MemoryStorage) Has(id objects.ObjectId) (bool, error) { } func (ms MemoryStorage) Set(id objects.ObjectId, typ objects.ObjectType, raw []byte) error { - ms.objects[id.String()] = raw + ms.objects[id.String()] = copyBytes(raw) ms.bytype[typ] = append(ms.bytype[typ], id) return nil -- cgit v1.2.3-70-g09d2