File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,6 +131,12 @@ package body Tls_Client with SPARK_Mode is
131131
132132 Result : WolfSSL.Subprogram_Result;
133133 begin
134+ Result := WolfSSL.Initialize;
135+ if Result = Failure then
136+ Put_Line (" ERROR: Failed to initialize the WolfSSL library." );
137+ return ;
138+ end if ;
139+
134140 if Argument_Count < 1 then
135141 Put_Line (" usage: tcl_client <IPv4 address>" );
136142 return ;
@@ -297,7 +303,10 @@ package body Tls_Client with SPARK_Mode is
297303 SPARK_Sockets.Close_Socket (C);
298304 WolfSSL.Free (Ssl);
299305 WolfSSL.Free (Context => Ctx);
300- WolfSSL.Finalize;
306+ Result := WolfSSL.Finalize;
307+ if Result = Failure then
308+ Put_Line (" ERROR: Failed to finalize the WolfSSL library." );
309+ end if ;
301310 end Run ;
302311
303312end Tls_Client ;
Original file line number Diff line number Diff line change @@ -111,6 +111,12 @@ package body Tls_Server with SPARK_Mode is
111111 Input : WolfSSL.Read_Result;
112112 Option : Option_Type;
113113 begin
114+ Result := WolfSSL.Initialize;
115+ if Result = Failure then
116+ Put_Line (" ERROR: Failed to initialize the WolfSSL library." );
117+ return ;
118+ end if ;
119+
114120 SPARK_Sockets.Create_Socket (Socket => L);
115121 if not L.Exists then
116122 Put_Line (" ERROR: Failed to create socket." );
@@ -308,7 +314,11 @@ package body Tls_Server with SPARK_Mode is
308314 end loop ;
309315 SPARK_Sockets.Close_Socket (L);
310316 WolfSSL.Free (Context => Ctx);
311- WolfSSL.Finalize;
317+ Result := WolfSSL.Finalize;
318+ if Result = Failure then
319+ Put_Line (" ERROR: Failed to finalize the WolfSSL library." );
320+ return ;
321+ end if ;
312322 end Run ;
313323
314324end Tls_Server ;
Original file line number Diff line number Diff line change @@ -44,11 +44,23 @@ package body WolfSSL is
4444 External_Name => " wolfSSL_Cleanup" ,
4545 Import => True;
4646
47- procedure Finalize is
47+ function Initialize return Subprogram_Result is
48+ Result : constant int := Initialize_WolfSSL;
49+ begin
50+ if Result = WOLFSSL_SUCCESS then
51+ return Success;
52+ else
53+ return Failure;
54+ end if ;
55+ end Initialize ;
56+
57+ function Finalize return Subprogram_Result is
4858 Result : constant int := Finalize_WolfSSL;
4959 begin
50- if Result /= WOLFSSL_SUCCESS then
51- raise Cleanup_Error;
60+ if Result = WOLFSSL_SUCCESS then
61+ return Success;
62+ else
63+ return Failure;
5264 end if ;
5365 end Finalize ;
5466
@@ -728,9 +740,4 @@ package body WolfSSL is
728740 Ssl := null ;
729741 end Free ;
730742
731- Result : constant int := Initialize_WolfSSL;
732- begin
733- if Result /= WOLFSSL_SUCCESS then
734- raise Initialization_Error;
735- end if ;
736743end WolfSSL ;
Original file line number Diff line number Diff line change @@ -25,26 +25,20 @@ with Interfaces.C;
2525-- the API of this package is used correctly.
2626package WolfSSL with SPARK_Mode is
2727
28- procedure Finalize ;
29- -- Must be called before application exit.
28+ type Subprogram_Result is (Success, Failure);
3029
31- Initialization_Error : exception ;
32- -- Raised if error was encountered during initialization of the
33- -- WolfSSL library. The WolfSSL libray is initialized during
34- -- elaboration time.
30+ function Initialize return Subprogram_Result;
31+ -- Must be called before usage of the WolfSSL library.
3532
36- Cleanup_Error : exception ;
37- -- Raised if error was encountered during application shutdown
38- -- and cleanup of resources allocated by WolfSSL has failed.
33+ function Finalize return Subprogram_Result;
34+ -- Must be called before application exit to cleanup resources.
3935
4036 subtype char_array is Interfaces.C.char_array; -- Remove?
4137
4238 subtype Byte_Type is Interfaces.C.char;
4339 subtype Byte_Index is Interfaces.C.size_t range 0 .. 16_000 ;
4440 subtype Byte_Array is Interfaces.C.char_array;
4541
46- type Subprogram_Result is (Success, Failure);
47-
4842 type Context_Type is limited private ;
4943
5044 function Is_Valid (Context : Context_Type) return Boolean;
You can’t perform that action at this time.
0 commit comments