From 0898d441cb42e09092be7772f4c24fd10e36fa72 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 15 Nov 2011 13:53:03 +0100 Subject: Use libcrypto.so instead of libssl.so in the ffi part of tutorial --- doc/tutorial/ffi.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'doc/tutorial') diff --git a/doc/tutorial/ffi.md b/doc/tutorial/ffi.md index 4c4ad0eba7b..0a1ba128e51 100644 --- a/doc/tutorial/ffi.md +++ b/doc/tutorial/ffi.md @@ -15,7 +15,7 @@ OpenSSL libraries installed, it should 'just work'. use std; import std::{vec, str}; - native "cdecl" mod ssl { + native "cdecl" mod crypto { fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8; } @@ -27,8 +27,8 @@ OpenSSL libraries installed, it should 'just work'. fn sha1(data: str) -> str unsafe { let bytes = str::bytes(data); - let hash = ssl::SHA1(vec::unsafe::to_ptr(bytes), - vec::len(bytes), std::ptr::null()); + let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes), + vec::len(bytes), std::ptr::null()); ret as_hex(vec::unsafe::from_buf(hash, 20u)); } @@ -41,7 +41,7 @@ OpenSSL libraries installed, it should 'just work'. Before we can call `SHA1`, we have to declare it. That is what this part of the program is responsible for: - native "cdecl" mod ssl { + native "cdecl" mod crypto { fn SHA1(src: *u8, sz: uint, out: *u8) -> *u8; } @@ -49,10 +49,10 @@ A `native` module declaration tells the compiler that the program should be linked with a library by that name, and that the given list of functions are available in that library. -In this case, it'll change the name `ssl` to a shared library name in -a platform-specific way (`libssl.so` on Linux, for example), and link -that in. If you want the module to have a different name from the -actual library, you can say `native "cdecl" mod something = "ssl" { +In this case, it'll change the name `crypto` to a shared library name +in a platform-specific way (`libcrypto.so` on Linux, for example), and +link that in. If you want the module to have a different name from the +actual library, you can say `native "cdecl" mod something = "crypto" { ... }`. The `"cdecl"` word indicates the calling convention to use for @@ -94,8 +94,8 @@ The `sha1` function is the most obscure part of the program. fn sha1(data: str) -> str unsafe { let bytes = str::bytes(data); - let hash = ssl::SHA1(vec::unsafe::to_ptr(bytes), - vec::len(bytes), std::ptr::null()); + let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes), + vec::len(bytes), std::ptr::null()); ret as_hex(vec::unsafe::from_buf(hash, 20u)); } @@ -128,8 +128,8 @@ Rust's safety mechanisms. Let's look at our `sha1` function again. let bytes = str::bytes(data); - let hash = ssl::SHA1(vec::unsafe::to_ptr(bytes), - vec::len(bytes), std::ptr::null()); + let hash = crypto::SHA1(vec::unsafe::to_ptr(bytes), + vec::len(bytes), std::ptr::null()); ret as_hex(vec::unsafe::from_buf(hash, 20u)); The `str::bytes` function is perfectly safe, it converts a string to -- cgit 1.4.1-3-g733a5