| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  | ! Copyright (C) 2007, 2008, Slava Pestov, Elie CHAFTARI. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-11-23 02:00:29 -05:00
										 |  |  | USING: init kernel namespaces openssl.libcrypto openssl.libssl | 
					
						
							|  |  |  | sequences ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  | IN: openssl | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ! This code is based on http://www.rtfm.com/openssl-examples/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SINGLETON: openssl | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-12 19:53:22 -04:00
										 |  |  | : (ssl-error-string) ( n -- string )
 | 
					
						
							|  |  |  |     ERR_clear_error f ERR_error_string ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : ssl-error-string ( -- string )
 | 
					
						
							|  |  |  |     ERR_get_error ERR_clear_error f ERR_error_string ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-13 19:24:46 -04:00
										 |  |  | : (ssl-error) ( -- * )
 | 
					
						
							|  |  |  |     ssl-error-string throw ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  | : ssl-error ( obj -- )
 | 
					
						
							| 
									
										
										
										
											2008-05-13 19:24:46 -04:00
										 |  |  |     { f 0 } member? [ (ssl-error) ] when ;
 | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : init-ssl ( -- )
 | 
					
						
							|  |  |  |     SSL_library_init ssl-error | 
					
						
							|  |  |  |     SSL_load_error_strings | 
					
						
							|  |  |  |     OpenSSL_add_all_digests | 
					
						
							|  |  |  |     OpenSSL_add_all_ciphers ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-31 01:07:40 -04:00
										 |  |  | SYMBOL: ssl-initialized? | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : maybe-init-ssl ( -- )
 | 
					
						
							| 
									
										
										
										
											2008-05-31 01:07:40 -04:00
										 |  |  |     ssl-initialized? get-global [ | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  |         init-ssl | 
					
						
							| 
									
										
										
										
											2008-05-31 01:07:40 -04:00
										 |  |  |         t ssl-initialized? set-global
 | 
					
						
							| 
									
										
										
										
											2008-05-11 18:41:54 -04:00
										 |  |  |     ] unless ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-31 01:07:40 -04:00
										 |  |  | [ f ssl-initialized? set-global ] "openssl" add-init-hook |