Commit 2a646916 authored by Valerii Hiora's avatar Valerii Hiora
Browse files

Handle recent breaking changes

- macro reform
- split of Show and String in formatter
- CString reform
- feature changes
parent 1ba10674
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ impl Reader for MemBio {
                IoError {
                    kind: OtherIoError,
                    desc: "MemBio read error",
                    detail: Some(format!("{}", SslError::get()))
                    detail: Some(format!("{:?}", SslError::get()))
                }
            };
            Err(err)
@@ -96,7 +96,7 @@ impl Writer for MemBio {
            Err(IoError {
                kind: OtherIoError,
                desc: "MemBio write error",
                detail: Some(format!("{}", SslError::get()))
                detail: Some(format!("{:?}", SslError::get()))
            })
        } else {
            Ok(())
+5 −7
Original line number Diff line number Diff line
use libc::{c_int, c_ulong, c_void};
use std::c_str::{CString, ToCStr};
use std::ffi::{CString, c_str_to_bytes};
use std::cmp::Ordering;
use std::{fmt, ptr};

@@ -88,7 +88,7 @@ impl BigNum {

    pub fn from_dec_str(s: &str) -> Result<BigNum, SslError> {
        BigNum::new().and_then(|v| unsafe {
            let c_str = s.to_c_str();
            let c_str = CString::from_slice(s.as_bytes());
            try_ssl!(ffi::BN_dec2bn(v.raw_ptr(), c_str.as_ptr()));
            Ok(v)
        })
@@ -96,7 +96,7 @@ impl BigNum {

    pub fn from_hex_str(s: &str) -> Result<BigNum, SslError> {
        BigNum::new().and_then(|v| unsafe {
            let c_str = s.to_c_str();
            let c_str = CString::from_slice(s.as_bytes());
            try_ssl!(ffi::BN_hex2bn(v.raw_ptr(), c_str.as_ptr()));
            Ok(v)
        })
@@ -421,8 +421,7 @@ impl BigNum {
        unsafe {
            let buf = ffi::BN_bn2dec(self.raw());
            assert!(!buf.is_null());
            let c_str = CString::new(buf, false);
            let str = c_str.as_str().unwrap().to_string();
            let str = String::from_utf8(c_str_to_bytes(&buf).to_vec()).unwrap();
            ffi::CRYPTO_free(buf as *mut c_void);
            str
        }
@@ -432,8 +431,7 @@ impl BigNum {
        unsafe {
            let buf = ffi::BN_bn2hex(self.raw());
            assert!(!buf.is_null());
            let c_str = CString::new(buf, false);
            let str = c_str.as_str().unwrap().to_string();
            let str = String::from_utf8(c_str_to_bytes(&buf).to_vec()).unwrap();
            ffi::CRYPTO_free(buf as *mut c_void);
            str
        }

src/lib.rs

100644 → 100755
+1 −1
Original line number Diff line number Diff line
#![feature(macro_rules, unsafe_destructor, globs, associated_types, default_type_params, old_orphan_check)]
#![feature(unsafe_destructor, old_orphan_check)]
#![crate_name="openssl"]
#![crate_type="rlib"]
#![crate_type="dylib"]

src/macros.rs

100644 → 100755
+1 −1
Original line number Diff line number Diff line
#![macro_escape]
#![macro_use]

macro_rules! try_ssl_stream {
    ($e:expr) => (
+14 −5
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ pub use self::OpensslError::*;

use libc::c_ulong;
use std::error;
use std::ffi::c_str_to_bytes;
use std::io::IoError;
use std::c_str::CString;

use ffi;

@@ -51,15 +51,24 @@ pub enum OpensslError {
}

fn get_lib(err: c_ulong) -> String {
    unsafe { CString::new(ffi::ERR_lib_error_string(err), false) }.to_string()
    unsafe {
        let bytes = c_str_to_bytes(&ffi::ERR_lib_error_string(err)).to_vec();
        String::from_utf8(bytes).unwrap()
    }
}

fn get_func(err: c_ulong) -> String {
    unsafe { CString::new(ffi::ERR_func_error_string(err), false).to_string() }
    unsafe {
        let bytes = c_str_to_bytes(&ffi::ERR_func_error_string(err)).to_vec();
        String::from_utf8(bytes).unwrap()
    }
}

fn get_reason(err: c_ulong) -> String {
    unsafe { CString::new(ffi::ERR_reason_error_string(err), false).to_string() }
    unsafe {
        let bytes = c_str_to_bytes(&ffi::ERR_reason_error_string(err)).to_vec();
        String::from_utf8(bytes).unwrap()
    }
}

impl SslError {
Loading