@@ -11,63 +11,9 @@ package body SHA256_Bindings_Tests is
1111 -- Helpers
1212 -- --------------------------------------------------------------------------
1313
14- procedure Assert_Text_Matches_Hash
15- (Hash : WolfSSL.SHA256_Hash;
16- Text : WolfSSL.SHA256_As_String;
17- Msg : String);
18-
1914 procedure Compute_SHA256
2015 (Input : WolfSSL.Byte_Array;
2116 Hash : out WolfSSL.SHA256_Hash;
22- Text : out WolfSSL.SHA256_As_String;
23- Result : out Integer);
24-
25- procedure Assert_Text_Matches_Hash
26- (Hash : WolfSSL.SHA256_Hash;
27- Text : WolfSSL.SHA256_As_String;
28- Msg : String)
29- is
30- use type WolfSSL.Byte_Array;
31-
32- Expected : constant WolfSSL.Byte_Array := Test_Support.Hex_Bytes (Text);
33- Actual : WolfSSL.Byte_Array (Expected'Range );
34- H : WolfSSL.Byte_Index := Hash'First;
35- begin
36- -- Copy bytes out of the hash into the expected-range buffer.
37- -- Do not assume Hash and Expected share the same index range.
38- for I in Actual'Range loop
39- Actual (I) := Hash (H);
40- H := WolfSSL.Byte_Index'Succ (H);
41- end loop ;
42- AUnit.Assertions.Assert
43- (Text'Length = 64 ,
44- Msg & " : expected 64 hex chars, got" & Integer'Image (Text'Length));
45-
46- -- `Finalize_SHA256` should generate uppercase hex, validate that expectation.
47- for J in Text'Range loop
48- declare
49- C : constant Character := Text (J);
50- begin
51- if C in ' 0' .. ' 9' or else C in ' A' .. ' F' then
52- null ;
53- else
54- AUnit.Assertions.Assert
55- (False,
56- Msg & " : expected uppercase hex at pos" &
57- Integer'Image (J));
58- end if ;
59- end ;
60- end loop ;
61-
62- AUnit.Assertions.Assert
63- (Actual = Expected,
64- Msg & " : Text/Hash mismatch" );
65- end Assert_Text_Matches_Hash ;
66-
67- procedure Compute_SHA256
68- (Input : WolfSSL.Byte_Array;
69- Hash : out WolfSSL.SHA256_Hash;
70- Text : out WolfSSL.SHA256_As_String;
7117 Result : out Integer)
7218 is
7319 SHA256 : WolfSSL.SHA256_Type;
@@ -90,7 +36,6 @@ package body SHA256_Bindings_Tests is
9036 WolfSSL.Finalize_SHA256
9137 (SHA256 => SHA256,
9238 Hash => Hash,
93- Text => Text,
9439 Result => R);
9540
9641 Result := R;
@@ -106,53 +51,67 @@ package body SHA256_Bindings_Tests is
10651 pragma Unreferenced (F);
10752
10853 Hash : WolfSSL.SHA256_Hash;
109- Text : WolfSSL.SHA256_As_String;
11054 R : Integer;
11155
11256 Input : constant WolfSSL.Byte_Array := Test_Support.Bytes (" asdf" );
11357
114- Expected_Text : constant WolfSSL.SHA256_As_String :=
115- Test_Support.SHA256_Text
116- (" F0E4C2F76C58916EC258F246851BEA091D14D4247A2FC3E18694461B1816E13B" );
58+ Expected_Hash : constant WolfSSL.Byte_Array :=
59+ Test_Support.Hex_Bytes
60+ (Test_Support.SHA256_Text
61+ (" F0E4C2F76C58916EC258F246851BEA091D14D4247A2FC3E18694461B1816E13B" ));
11762 begin
118- Compute_SHA256 (Input => Input, Hash => Hash, Text => Text, Result => R);
63+ Compute_SHA256 (Input => Input, Hash => Hash, Result => R);
11964
12065 Test_Support.Assert_Success (R, " SHA256(asdf)" );
12166
122- AUnit.Assertions.Assert
123- (Text = Expected_Text,
124- " SHA256('asdf') hex mismatch. Got: " & Text);
125-
126- Assert_Text_Matches_Hash
127- (Hash => Hash, Text => Text, Msg => " SHA256('asdf')" );
67+ -- Compare the hash bytes
68+ declare
69+ use type WolfSSL.Byte_Array;
70+ Hash_Bytes : WolfSSL.Byte_Array (1 .. 32 );
71+ J : WolfSSL.Byte_Index := 1 ;
72+ begin
73+ for I in Hash'Range loop
74+ Hash_Bytes (J) := Hash (I);
75+ J := WolfSSL.Byte_Index'Succ (J);
76+ end loop ;
77+ AUnit.Assertions.Assert
78+ (Hash_Bytes = Expected_Hash,
79+ " SHA256('asdf') hash mismatch" );
80+ end ;
12881 end Test_SHA256_Asdf_Known_Vector ;
12982
13083 procedure Test_SHA256_Empty_Message (F : in out Fixture) is
13184 pragma Unreferenced (F);
13285
13386 Hash : WolfSSL.SHA256_Hash;
134- Text : WolfSSL.SHA256_As_String;
13587 R : Integer;
13688
13789 -- Represent empty input as a null range, matching the existing test style.
13890 Empty : constant WolfSSL.Byte_Array := (1 .. 0 => <>);
13991
140- Expected_Text : constant WolfSSL.SHA256_As_String :=
141- Test_Support.SHA256_Text
142- (" E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" );
92+ Expected_Hash : constant WolfSSL.Byte_Array :=
93+ Test_Support.Hex_Bytes
94+ (Test_Support.SHA256_Text
95+ (" E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855" ));
14396 begin
144- Compute_SHA256 (Input => Empty, Hash => Hash, Text => Text, Result => R);
97+ Compute_SHA256 (Input => Empty, Hash => Hash, Result => R);
14598
14699 Test_Support.Assert_Success (R, " SHA256(empty)" );
147100
148- AUnit.Assertions.Assert
149- (Text = Expected_Text,
150- " SHA256('') hex mismatch. Got: " & Text);
151-
152- Assert_Text_Matches_Hash
153- (Hash => Hash,
154- Text => Text,
155- Msg => " SHA256('')" );
101+ -- Compare the hash bytes
102+ declare
103+ use type WolfSSL.Byte_Array;
104+ Hash_Bytes : WolfSSL.Byte_Array (1 .. 32 );
105+ J : WolfSSL.Byte_Index := 1 ;
106+ begin
107+ for I in Hash'Range loop
108+ Hash_Bytes (J) := Hash (I);
109+ J := WolfSSL.Byte_Index'Succ (J);
110+ end loop ;
111+ AUnit.Assertions.Assert
112+ (Hash_Bytes = Expected_Hash,
113+ " SHA256('') hash mismatch" );
114+ end ;
156115 end Test_SHA256_Empty_Message ;
157116
158117 -- --------------------------------------------------------------------------
0 commit comments