-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gustavo Chain
committed
Dec 14, 2020
1 parent
6373ce9
commit b63e269
Showing
6 changed files
with
152 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package etebase | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/etesync/etebase-go/internal/codec" | ||
"github.com/google/uuid" | ||
) | ||
|
||
const ( | ||
CurrentVersion uint8 = 1 | ||
) | ||
|
||
type CollectionAccessLevel uint32 | ||
|
||
const ( | ||
ReadOnly CollectionAccessLevel = iota | ||
Admin | ||
ReadWrite | ||
) | ||
|
||
type EncryptedCollection struct { | ||
Item EncryptedItem `msgpack:"item"` | ||
AccessLevel CollectionAccessLevel `msgpack:"accessLevel"` | ||
Type []byte `msgpack:"collectionType"` | ||
Key []byte `msgpack:"collectionKey"` | ||
Stoken string `msgpack:"stoken"` | ||
} | ||
|
||
func NewCollection(cType string, meta interface{}, content []byte) (*EncryptedCollection, error) { | ||
metaBytes, err := codec.Marshal(meta) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uid1 := uuid.New().String() | ||
uid2 := uuid.New().String() | ||
return &EncryptedCollection{ | ||
Item: EncryptedItem{ | ||
UID: uid1, | ||
Version: CurrentVersion, | ||
Content: EncryptedRevision{ | ||
UID: uid2, | ||
Meta: metaBytes, | ||
Chunks: []ChunkArrayItem{}, | ||
}, | ||
}, | ||
Type: []byte(time.Now().String()), | ||
Key: []byte("key"), | ||
}, nil | ||
} | ||
|
||
type EncryptedItem struct { | ||
UID string `msgpack:"uid"` | ||
Version uint8 `msgpack:"version"` | ||
Etag []byte `msgpack:"etag"` | ||
Content EncryptedRevision `msgpack:"content"` | ||
} | ||
|
||
type EncryptedRevision struct { | ||
UID string `msgpack:"uid"` | ||
Meta []byte `msgpack:"meta"` | ||
Deleted bool `msgpack:"deleted"` | ||
Chunks []ChunkArrayItem `msgpack:"chunks"` | ||
} | ||
|
||
type ChunkArrayItem struct { | ||
Data string | ||
Option []byte | ||
} | ||
|
||
func (c ChunkArrayItem) MarshalMsgpack() ([]byte, error) { | ||
return codec.Marshal([]interface{}{ | ||
c.Data, c.Option, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters