Link Search Menu Expand Document

4.2 Datastore

As stated in the Threat Model, Datastore is an untrusted server that provides persistent storage. Since Datastore can be malicious, you must protect the confidentiality and integrity of any sensitive data you store in it.

Datastore is structured as a key-value store. In this context, key refers to a unique identifier that is used to identify a specific entry in datastore, and does not refer to a cryptographic key.

All key-value entries in Datastore exist in a single, global namespace and Datastore does not perform any access control. Therefore, any value entry can be overwritten or deleted by any user who knows the corresponding storage key.

Note that the storage key must be a UUID.

An implementation of Datastore is provided for you (see source code in userlib) and is already imported into client.go.

The client application can interact with Datastore using the API documented below.


DatastoreSet

userlib.DatastoreSet(key UUID, value []byte)

Stores the given value at the given storage key.

Unlike the Keystore, key-value entries in the Datastore are mutable; if key already maps to a value, then value can be overwritten with a call to DatastoreSet() using the same key.

Parameters
key (UUID) – Unique identifier used to index value in the datastore
value ([]byte]) – Value

Example:

UUID := uuid.New()
data := []byte("hello world")
userlib.DatastoreSet(UUID, data)

DatastoreGet

userlib.DatastoreGet(key UUID) (value []byte, ok bool)

Return the value corresponding to the given key.

If a value does exist at the given key, then ok will be true; otherwise, it will be false.

Parameters
key (UUID)
Return type

value ([]byte), ok (bool)

Example:

location := uuid.New()
data := []byte("hello world")
userlib.DatastoreSet(UUID, data)
download_data, ok := userlib.DatastoreGet(location)
if !ok || !bytes.Equal(download_data, data) {
    panic("the data should exist, and it should match")
}

DatastoreDelete

userlib.DatastoreDelete(key UUID)

Delete the given key-value pair from the Datastore, if it exists.

Parameters
key (UUID)

Example:

location := uuid.New()
data := []byte("hello world")
userlib.DatastoreSet(location, data)
userlib.DatastoreDelete(location)
_, ok := userlib.DatastoreGet(location)
if ok {
    panic("the data should have been deleted")
}