File : hash_streams.ads


   1 with Ada.Streams; use Ada.Streams;
   2 with Hashes; use Hashes;
   3 with GNAT.SHA256;
   4 
   5 
   6 generic
   7    -- no arguments -- genericized solely to satisfy fascist anti-pointer rules
   8 package Hash_Streams is
   9    
  10    type Stream_Access is not null access all Ada.Streams.Root_Stream_Type'Class;
  11    
  12    type Hash_Stream(Stream : Stream_Access)
  13       is new Ada.Streams.Root_Stream_Type with private;
  14    
  15    type Hash_Stream_Access is not null access all Hash_Stream;
  16    
  17    overriding
  18    procedure Read(Stream : in out Hash_Stream;
  19                   Item   : out Stream_Element_Array;
  20                   Last   : out Stream_Element_Offset);
  21    
  22    overriding
  23    procedure Write(Stream : in out Hash_Stream;
  24                    Item   : in Stream_Element_Array);
  25    
  26    function GetDoubleHash(Stream : in Hash_Stream) return SHA256Hash;
  27    
  28    function GetCount(Stream : in Hash_Stream) return Natural;
  29    
  30 private
  31    
  32    type Hash_Stream(Stream : Stream_Access) is new
  33      Ada.Streams.Root_Stream_Type with
  34       record
  35          S : Stream_Access := Stream;
  36          Ctx : GNAT.SHA256.Context := GNAT.SHA256.Initial_Context;
  37          Count : Natural := 0;
  38       end record;
  39    
  40 end Hash_Streams;