diff options
| author | Valerii Hiora <[email protected]> | 2014-10-07 15:09:20 +0300 |
|---|---|---|
| committer | Valerii Hiora <[email protected]> | 2014-10-07 19:58:52 +0300 |
| commit | 3ba768bc288031964994e39d0fa08607fccf728e (patch) | |
| tree | 65fefee9f35059aa0f33af627e57d0031236b422 /src/bio | |
| parent | Merge pull request #69 from vhbit/bn-zero-fix (diff) | |
| download | rust-openssl-3ba768bc288031964994e39d0fa08607fccf728e.tar.xz rust-openssl-3ba768bc288031964994e39d0fa08607fccf728e.zip | |
Fixed incorrect EOF handling in MemBio, added error description
Actually, EOF wasn't handled at all and it caused `mem_bio.read_to_end()` to fail. Which in turn failed all `write_pem` implementations.
Diffstat (limited to 'src/bio')
| -rw-r--r-- | src/bio/mod.rs | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/bio/mod.rs b/src/bio/mod.rs index 5c5e8df0..a6dc9dc2 100644 --- a/src/bio/mod.rs +++ b/src/bio/mod.rs @@ -1,5 +1,5 @@ use libc::{c_void, c_int}; -use std::io::{IoResult, IoError, OtherIoError}; +use std::io::{EndOfFile, IoResult, IoError, OtherIoError}; use std::io::{Reader, Writer}; use std::ptr; @@ -62,9 +62,22 @@ impl Reader for MemBio { buf.len() as c_int) }; - if ret < 0 { - // FIXME: provide details from OpenSSL - Err(IoError{kind: OtherIoError, desc: "mem bio read error", detail: None}) + if ret <= 0 { + let is_eof = unsafe { ffi::BIO_eof(self.bio) }; + let err = if is_eof { + IoError { + kind: EndOfFile, + desc: "MemBio EOF", + detail: None + } + } else { + IoError { + kind: OtherIoError, + desc: "MemBio read error", + detail: Some(format!("{}", SslError::get())) + } + }; + Err(err) } else { Ok(ret as uint) } @@ -78,8 +91,11 @@ impl Writer for MemBio { buf.len() as c_int) }; if buf.len() != ret as uint { - // FIXME: provide details from OpenSSL - Err(IoError{kind: OtherIoError, desc: "mem bio write error", detail: None}) + Err(IoError { + kind: OtherIoError, + desc: "MemBio write error", + detail: Some(format!("{}", SslError::get())) + }) } else { Ok(()) } |