From 5492b8e46bebf5bdf13a87d8e6d9211f9bd66bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Fri, 13 Sep 2013 13:52:27 +0200 Subject: [PATCH] libcrypto: wrap more parts of the BIO_ api and add unit tests --- .../openssl/libcrypto/libcrypto-tests.factor | 24 +++++++++ basis/openssl/libcrypto/libcrypto.factor | 53 ++++++++----------- 2 files changed, 47 insertions(+), 30 deletions(-) create mode 100644 basis/openssl/libcrypto/libcrypto-tests.factor diff --git a/basis/openssl/libcrypto/libcrypto-tests.factor b/basis/openssl/libcrypto/libcrypto-tests.factor new file mode 100644 index 0000000000..0a896db511 --- /dev/null +++ b/basis/openssl/libcrypto/libcrypto-tests.factor @@ -0,0 +1,24 @@ +USING: + byte-arrays + kernel + openssl.libcrypto + sequences + splitting + strings + tools.test ; +IN: openssl.libcrypto.tests + +[ t ] [ "factorcode.org:80" BIO_new_connect bio_st? ] unit-test + +[ 1 ] [ + "factorcode.org:80" BIO_new_connect BIO_C_DO_STATE_MACHINE 0 f BIO_ctrl +] unit-test + +[ "HTTP/1.1 200 Document follows" ] [ + "factorcode.org:80" BIO_new_connect + [ BIO_C_DO_STATE_MACHINE 0 f BIO_ctrl drop ] + [ + [ "GET / HTTP/1.1\r\nHost: factorcode.org\r\n\r\n" BIO_puts drop ] + [ 1024 dup swapd 1023 BIO_read drop ] bi + ] bi >string "\r\n" split first +] unit-test diff --git a/basis/openssl/libcrypto/libcrypto.factor b/basis/openssl/libcrypto/libcrypto.factor index 3f5d1ac35c..b1f796c959 100644 --- a/basis/openssl/libcrypto/libcrypto.factor +++ b/basis/openssl/libcrypto/libcrypto.factor @@ -30,32 +30,23 @@ STRUCT: bio-method { destroy void* } { callback-ctrl void* } ; -STRUCT: bio - { method void* } - { callback void* } - { cb-arg void* } - { init int } - { shutdown int } - { flags int } - { retry-reason int } - { num int } - { ptr void* } - { next-bio void* } - { prev-bio void* } - { references int } - { num-read ulong } - { num-write ulong } - { crypto-ex-data-stack void* } - { crypto-ex-data-dummy int } ; - CONSTANT: BIO_NOCLOSE 0x00 CONSTANT: BIO_CLOSE 0x01 CONSTANT: RSA_3 0x3 CONSTANT: RSA_F4 0x10001 -CONSTANT: BIO_C_SET_SSL 109 -CONSTANT: BIO_C_GET_SSL 110 +CONSTANT: BIO_C_SET_CONNECT 100 +CONSTANT: BIO_C_DO_STATE_MACHINE 101 +CONSTANT: BIO_C_SET_NBIO 102 +CONSTANT: BIO_C_SET_PROXY_PARAM 103 +CONSTANT: BIO_C_SET_FD 104 +CONSTANT: BIO_C_GET_FD 105 +CONSTANT: BIO_C_SET_FILE_PTR 106 +CONSTANT: BIO_C_GET_FILE_PTR 107 +CONSTANT: BIO_C_SET_FILENAME 108 +CONSTANT: BIO_C_SET_SSL 109 +CONSTANT: BIO_C_GET_SSL 110 LIBRARY: libcrypto @@ -90,25 +81,27 @@ STRUCT: bio_st { init int } { shutdown int } { flags int } - { retry_reason int } + { retry-reason int } { num int } { ptr void* } - { next_bio bio_st* } - { prev_bio bio_st* } + { next-bio bio_st* } + { prev-bio bio_st* } { references int } - { num_read ulong } - { num_write ulong } - { ex_data CRYPTO_EX_DATA } ; + { num-read ulong } + { num-write ulong } + { ex-data CRYPTO_EX_DATA } ; TYPEDEF: bio_st BIO -FUNCTION: bio* BIO_new_file ( c-string filename, c-string mode ) ; +FUNCTION: BIO* BIO_new_file ( c-string filename, c-string mode ) ; -FUNCTION: int BIO_printf ( bio* bio, c-string format ) ; +FUNCTION: int BIO_printf ( BIO* bio, c-string format ) ; FUNCTION: long BIO_ctrl ( void* bio, int cmd, long larg, void* parg ) ; FUNCTION: BIO* BIO_new_socket ( int fd, int close-flag ) ; +FUNCTION: BIO* BIO_new_connect ( c-string name ) ; + FUNCTION: void* BIO_new ( void* method ) ; FUNCTION: int BIO_set ( void* bio, void* method ) ; @@ -117,13 +110,13 @@ FUNCTION: int BIO_free ( void* bio ) ; FUNCTION: void* BIO_push ( void* bio, void* append ) ; -FUNCTION: int BIO_read ( void* b, void* buf, int len ) ; +FUNCTION: int BIO_read ( BIO* bio, void* buf, int len ) ; FUNCTION: int BIO_gets ( void* b, c-string buf, int size ) ; FUNCTION: int BIO_write ( void* b, void* buf, int len ) ; -FUNCTION: int BIO_puts ( void* bp, c-string buf ) ; +FUNCTION: int BIO_puts ( BIO* bio, c-string buf ) ; FUNCTION: ulong ERR_get_error ( ) ;