diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-11-15 13:53:03 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-11-15 13:53:03 +0100 |
| commit | 0898d441cb42e09092be7772f4c24fd10e36fa72 (patch) | |
| tree | a191db867a03ceb791165e078600efc20109e02b /doc/tutorial | |
| parent | a09dcd94c5809bd5cbedd5c06218e8db25c2881a (diff) | |
| download | rust-0898d441cb42e09092be7772f4c24fd10e36fa72.tar.gz rust-0898d441cb42e09092be7772f4c24fd10e36fa72.zip | |
Use libcrypto.so instead of libssl.so in the ffi part of tutorial
Diffstat (limited to 'doc/tutorial')
| -rw-r--r-- | doc/tutorial/ffi.md | 24 |
1 files changed, 12 insertions, 12 deletions
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 |
