-
Notifications
You must be signed in to change notification settings - Fork 0
/
db-item.ads
112 lines (93 loc) · 3.58 KB
/
db-item.ads
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
with Ada.Streams;
use Ada.Streams;
with Ada.Containers.Indefinite_Ordered_Maps;
with DB.Key;
with Bupstash_Types;
with Tree.HTree_LL;
package DB.Item is
type Item is tagged limited private;
function Init(Key: in DB.Key.Key; Item_File: in String) return Item;
procedure Print(Ctx: in Item);
function Has_XID(Ctx: in Item; Cmp: in Bupstash_Types.XID)
return Boolean;
function Has_Index_Tree(Ctx: in Item) return Boolean;
function Get_Index_Size(Ctx: in Item) return Bupstash_Types.U64;
function Init_HTree_Reader_For_Index_Tree(Ctx: in Item) return
Tree.HTree_LL.Tree_Reader;
function Init_HTree_Reader_For_Data_Tree(Ctx: in Item) return
Tree.HTree_LL.Tree_Reader;
function Derive_Data_Hash_Key(Ctx: in Item; Key: in DB.Key.Key)
return Bupstash_Types.Hash_Key;
function Derive_Index_Hash_Key(Ctx: in Item; Key: in DB.Key.Key)
return Bupstash_Types.Hash_Key;
private
package String_Ordered_Maps is new Ada.Containers.
Indefinite_Ordered_Maps(Key_Type => String,
Element_Type => String);
use String_Ordered_Maps;
Item_Buf_Size: constant Ada.Streams.Stream_Element_Offset := 4096;
-- src/oplog.rs
-- pub struct HTreeMetadata {
-- pub height: serde_bare::Uint,
-- pub data_chunk_count: serde_bare::Uint,
-- pub address: Address,
-- }
type H_Tree_Metadata is tagged limited record
Height: Bupstash_Types.U64;
Data_Chunk_Count: Bupstash_Types.U64;
Address: Bupstash_Types.Address;
end record;
-- src/oplog.rs
-- pub struct V3PlainTextItemMetadata {
-- pub primary_key_id: Xid,
-- pub unix_timestamp_millis: u64,
-- pub data_tree: HTreeMetadata,
-- pub index_tree: Option<HTreeMetadata>,
-- }
type V3_Plain_Text_Item_Metadata is limited record
Primary_Key_ID: Bupstash_Types.XID;
Unix_Timestamp_Millis: Bupstash_Types.U64;
Data_Tree: H_Tree_Metadata;
Has_Index_Tree: Boolean;
Index_Tree: H_Tree_Metadata;
end record;
-- src/oplog.rs
-- #[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
-- pub struct V3SecretItemMetadata {
-- pub plain_text_hash: [u8; crypto::HASH_BYTES],
-- pub send_key_id: Xid,
-- pub index_hash_key_part_2: crypto::PartialHashKey,
-- pub data_hash_key_part_2: crypto::PartialHashKey,
-- pub tags: std::collections::BTreeMap<String, String>,
-- pub data_size: serde_bare::Uint,
-- pub index_size: serde_bare::Uint,
-- }
type V3_Secret_Item_Metadata is limited record
Plain_Text_Hash: Bupstash_Types.Hash;
Send_Key_ID: Bupstash_Types.XID;
Index_Hash_Key_Part_2: Bupstash_Types.Partial_Hash_Key;
Data_Hash_Key_Part_2: Bupstash_Types.Partial_Hash_Key;
Tags: Map;
Data_Size: Bupstash_Types.U64;
Index_Size: Bupstash_Types.U64;
end record;
type Item is tagged limited record
ID: Bupstash_Types.XID;
Plain: V3_Plain_Text_Item_Metadata;
Decrypted: V3_Secret_Item_Metadata;
end record;
procedure Decode_Plain_Text_Item_Metadata(
Raw: in Ada.Streams.Stream_Element_Array;
Encrypted_Length: out Bupstash_Types.U64;
Offset: out Ada.Streams.Stream_Element_Offset;
Ret: out V3_Plain_Text_Item_Metadata);
procedure Decrypt_Secret_Item_Metadata(Key: in DB.Key.Key;
Raw: in Stream_Element_Array;
Ret: out V3_Secret_Item_Metadata);
procedure Print(Ctx: in H_Tree_Metadata);
function Init_HTree_Reader_For_Meta(M: in H_Tree_Metadata) return
Tree.HTree_LL.Tree_Reader;
function Derive_Hash_Key(Part_1, Part_2:
in Bupstash_Types.Partial_Hash_Key)
return Bupstash_Types.Hash_Key;
end DB.Item;