|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| pragma SPARK_Mode (On);
|
|
|
| with SEB_Types;
|
| use SEB_Types;
|
|
|
| package SEB_Kernel is
|
|
|
|
|
| type Kernel_Handle is private;
|
|
|
|
|
| procedure Initialize_Kernel
|
| (Handle : out Kernel_Handle;
|
| Initial_Segment_Id : Unsigned_64;
|
| Initial_Segment_Sequence : Unsigned_64)
|
| with Global => null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| procedure Append_Event
|
| (Handle : in out Kernel_Handle;
|
| Header : Event_Header;
|
| Payload : Unsigned_8_Array;
|
| Footer : Event_Footer;
|
| Committed_Offset : out Segment_Offset)
|
| with Global => null,
|
| Pre => (
|
| Is_Valid_Header (Header) and
|
| Payload'Length = Natural (Header.Payload_Size) and
|
| Payload'Length <= Natural (Payload_Max_Size)
|
| ),
|
| Post => (
|
| Committed_Offset >= Min_Offset and
|
| Committed_Offset <= Max_Offset
|
| );
|
|
|
|
|
|
|
|
|
|
|
|
|
| function Verify_Signature
|
| (Hash : Hash_Type;
|
| Signature : Signature_Type;
|
| Public_Key : Public_Key_Type)
|
| return Verification_Status
|
| with Global => null,
|
| Post => (
|
| Verify_Signature'Result = Valid or
|
| Verify_Signature'Result = Invalid_Signature
|
| );
|
|
|
|
|
|
|
|
|
|
|
|
|
| function Verify_Hash
|
| (Header : Event_Header;
|
| Payload : Unsigned_8_Array;
|
| Expected_Hash : Hash_Type)
|
| return Verification_Status
|
| with Global => null,
|
| Pre => Payload'Length = Natural (Header.Payload_Size),
|
| Post => (
|
| Verify_Hash'Result = Valid or
|
| Verify_Hash'Result = Invalid_Hash
|
| );
|
|
|
|
|
|
|
|
|
|
|
|
|
| procedure Verify_Chain
|
| (Handle : Kernel_Handle;
|
| Valid : out Boolean;
|
| Events_Checked : out Unsigned_64)
|
| with Global => null,
|
| Post => (
|
| Valid = False or
|
| Events_Checked > 0
|
| );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| procedure Rotate_Segment
|
| (Handle : in out Kernel_Handle;
|
| New_Segment_Id : Unsigned_64;
|
| New_Segment_Sequence : Unsigned_64;
|
| Segment_Rotation_Offset : out Segment_Offset)
|
| with Global => null,
|
| Pre => New_Segment_Sequence > 0,
|
| Post => Segment_Rotation_Offset = 0;
|
|
|
|
|
|
|
| function Get_Current_Segment_Id (Handle : Kernel_Handle) return Unsigned_64
|
| with Global => null;
|
|
|
| function Get_Current_Sequence (Handle : Kernel_Handle) return Unsigned_64
|
| with Global => null;
|
|
|
| function Get_Current_Tip_Hash (Handle : Kernel_Handle) return Hash_Type
|
| with Global => null;
|
|
|
| function Get_Current_Tip_Offset (Handle : Kernel_Handle) return Segment_Offset
|
| with Global => null;
|
|
|
| function Get_Events_Sealed_Count (Handle : Kernel_Handle) return Unsigned_64
|
| with Global => null;
|
|
|
| function Get_Segments_Rotated_Count (Handle : Kernel_Handle) return Unsigned_64
|
| with Global => null;
|
|
|
|
|
| type Unsigned_8_Array is array (Natural range <>) of Unsigned_8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| procedure WORM_Flush (Handle : in out Kernel_Handle)
|
| with Global => null;
|
|
|
|
|
| Kernel_Error : exception;
|
| Integrity_Error : exception;
|
| Offset_Overflow : exception;
|
| Segment_Full_Error : exception;
|
|
|
| private
|
|
|
| type Kernel_Handle is record
|
| Current_Segment_Id : Unsigned_64 := 0;
|
| Current_Sequence : Unsigned_64 := 0;
|
| Tip_Hash : Hash_Type := (others => 0);
|
| Tip_Offset : Segment_Offset := 0;
|
| Events_Sealed : Unsigned_64 := 0;
|
| Segments_Rotated : Unsigned_64 := 0;
|
| end record;
|
|
|
| end SEB_Kernel;
|
|
|