awa_unit_2.4.0_59135a52/ada-keystore/src/keystore-repository-data.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
-----------------------------------------------------------------------
--  keystore-repository-data -- Data access and management for the keystore
--  Copyright (C) 2019, 2020 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Streams;
with Util.Streams;
with Keystore.IO;
with Keystore.Repository.Keys;

private package Keystore.Repository.Data is

   --  Start offset of the data entry descriptor in the data block.
   function Data_Entry_Offset (Index : in Natural) return IO.Block_Index is
      (IO.BT_DATA_START + Stream_Element_Offset (Index * DATA_ENTRY_SIZE) - DATA_ENTRY_SIZE - 1);

   --  Write the data in one or several blocks.
   procedure Add_Data (Manager     : in out Wallet_Repository;
                       Iterator    : in out Keys.Data_Key_Iterator;
                       Content     : in Ada.Streams.Stream_Element_Array;
                       Offset      : in out Interfaces.Unsigned_64);

   procedure Add_Data (Manager     : in out Wallet_Repository;
                       Iterator    : in out Keys.Data_Key_Iterator;
                       Content     : in out Util.Streams.Input_Stream'Class;
                       Offset      : in out Interfaces.Unsigned_64);

   --  Update the data fragments.
   procedure Update_Data (Manager      : in out Wallet_Repository;
                          Iterator     : in out Keys.Data_Key_Iterator;
                          Content      : in Ada.Streams.Stream_Element_Array;
                          Last_Pos     : out Ada.Streams.Stream_Element_Offset;
                          Offset       : in out Interfaces.Unsigned_64);

   procedure Update_Data (Manager       : in out Wallet_Repository;
                          Iterator      : in out Keys.Data_Key_Iterator;
                          Content       : in out Util.Streams.Input_Stream'Class;
                          End_Of_Stream : out Boolean;
                          Offset        : in out Interfaces.Unsigned_64);

   --  Erase the data fragments starting at the key iterator current position.
   procedure Delete_Data (Manager    : in out Wallet_Repository;
                          Iterator   : in out Keys.Data_Key_Iterator);

   --  Get the data associated with the named entry.
   procedure Get_Data (Manager    : in out Wallet_Repository;
                       Iterator   : in out Keys.Data_Key_Iterator;
                       Output     : out Ada.Streams.Stream_Element_Array);

   procedure Read (Manager  : in out Wallet_Repository;
                   Iterator : in out Keys.Data_Key_Iterator;
                   Offset   : in Ada.Streams.Stream_Element_Offset;
                   Output   : out Ada.Streams.Stream_Element_Array;
                   Last     : out Ada.Streams.Stream_Element_Offset);

   procedure Write (Manager  : in out Wallet_Repository;
                    Iterator : in out Keys.Data_Key_Iterator;
                    Offset   : in Ada.Streams.Stream_Element_Offset;
                    Content  : in Ada.Streams.Stream_Element_Array;
                    Result   : in out Interfaces.Unsigned_64);

   --  Get the data associated with the named entry and write it in the output stream.
   procedure Get_Data (Manager    : in out Wallet_Repository;
                       Iterator   : in out Keys.Data_Key_Iterator;
                       Output     : in out Util.Streams.Output_Stream'Class);

private

   --  Find the data block to hold a new data entry that occupies the given space.
   --  The first data block that has enough space is used otherwise a new block
   --  is allocated and initialized.
   procedure Allocate_Data_Block (Manager    : in out Wallet_Repository;
                                  Space      : in IO.Block_Index;
                                  Work       : in Workers.Data_Work_Access);

   --  Erase the data fragments starting at the key iterator current position.
   procedure Delete_Data (Manager    : in out Wallet_Repository;
                          Iterator   : in out Keys.Data_Key_Iterator;
                          Mark       : in out Keys.Data_Key_Marker);

end Keystore.Repository.Data;