This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_store.h
63 lines (54 loc) · 2.57 KB
/
object_store.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef P11NET_OBJECT_STORE_H_
#define P11NET_OBJECT_STORE_H_
#include <map>
#include <string>
#include <brillo/secure_blob.h>
#include "pkcs11/cryptoki.h"
namespace p11net {
// Pairs serialized object data with the object's privacy requirement.
struct ObjectBlob {
std::string blob;
bool is_private;
};
// An object store provides persistent storage of object blobs and internal
// blobs. All stored blobs are encrypted. Object properties (e.g. object class)
// are not necessarily encrypted.
class ObjectStore {
public:
virtual ~ObjectStore() {}
// These methods get and set internal persistent blobs. If a value has not yet
// been set for a particular blob, GetInternalBlob will provide an empty
// string. It is assumed that internal blobs are already encrypted and can be
// used to bootstrap the encryption of object blobs. Thus, they are not
// encrypted by the ObjectStore and they can be accessed and modified before
// SetEncryptionKey is called.
// blob_id - The value of this identifier must be managed by the caller.
// Only one blob can be set per blob_id (i.e. a subsequent call
// to SetInternalBlob with the same blob_id will overwrite the
// blob).
// blob - The blob data. This will not be encrypted.
virtual bool GetInternalBlob(int blob_id, std::string* blob) = 0;
virtual bool SetInternalBlob(int blob_id, const std::string& blob) = 0;
// SetEncryptionKey sets the encryption key used to encrypt all private object
// blobs. This method must be called before any object blob methods (e.g.
// InsertObjectBlob, DeleteObjectBlob, ...) can proceed successfully.
virtual bool SetEncryptionKey(const brillo::SecureBlob& key) = 0;
// Inserts a new blob.
virtual bool InsertObjectBlob(const ObjectBlob& blob,
int* blob_id) = 0;
// Deletes an existing object blob.
virtual bool DeleteObjectBlob(int blob_id) = 0;
// Deletes all object blobs.
virtual bool DeleteAllObjectBlobs() = 0;
// Updates (replaces) an existing object blob.
virtual bool UpdateObjectBlob(int blob_id, const ObjectBlob& blob) = 0;
// Loads all public non-internal objects.
virtual bool LoadPublicObjectBlobs(std::map<int, ObjectBlob>* blobs) = 0;
// Loads all private non-internal objects.
virtual bool LoadPrivateObjectBlobs(std::map<int, ObjectBlob>* blobs) = 0;
};
} // namespace p11net
#endif // P11NET_OBJECT_STORE_H_