2024-01-04 13:20:37 +00:00
|
|
|
package metadata
|
|
|
|
|
2024-01-05 12:00:42 +00:00
|
|
|
import (
|
|
|
|
"github.com/emirpasic/gods/maps/linkedhashmap"
|
|
|
|
"github.com/vmihailenco/msgpack/v5"
|
|
|
|
)
|
2024-01-04 13:20:37 +00:00
|
|
|
|
|
|
|
var _ SerializableMetadata = (*DirectoryReference)(nil)
|
|
|
|
|
|
|
|
type DirectoryReference struct {
|
|
|
|
Created uint64 `json:"created"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
EncryptedWriteKey Base64UrlBinary `json:"encryptedWriteKey,string"`
|
|
|
|
PublicKey Base64UrlBinary `json:"publicKey,string"`
|
2024-01-18 15:01:56 +00:00
|
|
|
EncryptionKey *Base64UrlBinary `json:"encryptionKey,string"`
|
2024-01-04 13:20:37 +00:00
|
|
|
Ext map[string]interface{} `json:"ext"`
|
2024-01-18 15:01:56 +00:00
|
|
|
URI string `json:"uri,omitempty"`
|
|
|
|
Key string `json:"key,omitempty"`
|
2024-01-04 13:20:37 +00:00
|
|
|
Size int64 `json:"size"`
|
|
|
|
}
|
|
|
|
|
2024-01-18 15:01:56 +00:00
|
|
|
func NewDirectoryReference(created uint64, name string, encryptedWriteKey, publicKey, encryptionKey Base64UrlBinary, ext map[string]interface{}) *DirectoryReference {
|
2024-01-04 13:20:37 +00:00
|
|
|
return &DirectoryReference{
|
|
|
|
Created: created,
|
|
|
|
Name: name,
|
|
|
|
EncryptedWriteKey: encryptedWriteKey,
|
|
|
|
PublicKey: publicKey,
|
2024-01-18 15:01:56 +00:00
|
|
|
EncryptionKey: &encryptionKey,
|
2024-01-04 13:20:37 +00:00
|
|
|
Ext: ext,
|
|
|
|
URI: "",
|
|
|
|
Key: "",
|
|
|
|
Size: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dr *DirectoryReference) EncodeMsgpack(enc *msgpack.Encoder) error {
|
2024-01-05 12:00:42 +00:00
|
|
|
dmap := &directoryReferenceSerializationMap{*linkedhashmap.New()}
|
|
|
|
|
|
|
|
dmap.Put(1, dr.Name)
|
|
|
|
dmap.Put(2, dr.Created)
|
|
|
|
dmap.Put(3, dr.PublicKey)
|
|
|
|
dmap.Put(4, dr.EncryptedWriteKey)
|
2024-01-04 13:20:37 +00:00
|
|
|
|
|
|
|
if dr.EncryptionKey != nil {
|
2024-01-05 12:00:42 +00:00
|
|
|
dmap.Put(5, dr.EncryptionKey)
|
2024-01-04 13:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if dr.Ext != nil {
|
2024-01-05 12:00:42 +00:00
|
|
|
dmap.Put(6, dr.Ext)
|
2024-01-04 13:20:37 +00:00
|
|
|
}
|
|
|
|
|
2024-01-05 12:00:42 +00:00
|
|
|
return enc.Encode(dmap)
|
2024-01-04 13:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dr *DirectoryReference) DecodeMsgpack(dec *msgpack.Decoder) error {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
l int
|
|
|
|
)
|
|
|
|
if l, err = dec.DecodeMapLen(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < l; i++ {
|
|
|
|
key, err := dec.DecodeInt8()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
value, err := dec.DecodeInterface()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
switch key {
|
|
|
|
case int8(1):
|
|
|
|
dr.Name = value.(string)
|
|
|
|
case int8(2):
|
|
|
|
dr.Created = value.(uint64)
|
|
|
|
case int8(3):
|
|
|
|
dr.PublicKey = value.([]byte)
|
|
|
|
case int8(4):
|
|
|
|
dr.EncryptedWriteKey = value.([]byte)
|
|
|
|
case int8(5):
|
2024-01-18 15:01:56 +00:00
|
|
|
dr.EncryptionKey = value.(*Base64UrlBinary)
|
2024-01-04 13:20:37 +00:00
|
|
|
case int8(6):
|
|
|
|
dr.Ext = value.(map[string]interface{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|