diff --git a/Cargo.toml b/Cargo.toml index ed889b8..f69067e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ path = "src/lib.rs" [dependencies] url = "1.7" -reqwest = "0.8" +reqwest = {version = "0.8", optional = true} rand = "0.4" base64 = "0.9" threadpool = "1.7" @@ -29,4 +29,6 @@ bitflags = "1.0.3" clippy = {version = "0.0", optional = true} [features] -dev = ["clippy"] \ No newline at end of file +default = ["online"] +dev = ["clippy"] +online = [] \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index ccef1c5..744fecd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,10 @@ #![cfg_attr(feature = "clippy", plugin(clippy))] #[macro_use] extern crate url; + +#[cfg(feature = "online")] extern crate reqwest; + extern crate base64; extern crate crypto; extern crate rand; @@ -27,7 +30,10 @@ use manager::{ Frame, Flags }; use config::{Config, Slot}; use yubicoerror::YubicoError; use libusb::{Context}; + +#[cfg(feature = "online")] use reqwest::header::{Headers, UserAgent}; + use std::io::prelude::*; use base64::{encode, decode}; use rand::{OsRng, Rng}; @@ -186,6 +192,7 @@ impl Yubico { } // Verify a provided OTP + #[cfg(feature = "online")] pub fn verify(&self, otp: S, config: Config) -> Result where S: Into { @@ -277,10 +284,12 @@ impl Yubico { } } +#[cfg(feature = "online")] pub struct RequestHandler { key: Vec, } +#[cfg(feature = "online")] impl RequestHandler { pub fn new(key: Vec) -> Self { RequestHandler { diff --git a/src/yubicoerror.rs b/src/yubicoerror.rs index 21a2723..44ba522 100644 --- a/src/yubicoerror.rs +++ b/src/yubicoerror.rs @@ -1,3 +1,5 @@ + +#[cfg(feature = "online")] extern crate reqwest; use std::error; @@ -9,7 +11,9 @@ use base64::DecodeError as base64Error; #[derive(Debug)] pub enum YubicoError { + #[cfg(feature = "online")] Network(reqwest::Error), + #[cfg(feature = "online")] HTTPStatusCode(reqwest::StatusCode), IOError(ioError), ChannelError(channelError), @@ -39,7 +43,9 @@ pub enum YubicoError { impl fmt::Display for YubicoError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { + #[cfg(feature = "online")] YubicoError::Network(ref err) => write!(f, "Connectivity error: {}", err), + #[cfg(feature = "online")] YubicoError::HTTPStatusCode(code) => write!(f, "Error found: {}", code), YubicoError::IOError(ref err) => write!(f, "IO error: {}", err), YubicoError::ChannelError(ref err) => write!(f, "Channel error: {}", err), @@ -71,7 +77,9 @@ impl fmt::Display for YubicoError { impl error::Error for YubicoError { fn description(&self) -> &str { match *self { + #[cfg(feature = "online")] YubicoError::Network(ref err) => err.description(), + #[cfg(feature = "online")] YubicoError::HTTPStatusCode(_) => "200 not received", YubicoError::IOError(ref err) => err.description(), YubicoError::ChannelError(ref err) => err.description(), @@ -101,7 +109,9 @@ impl error::Error for YubicoError { fn cause(&self) -> Option<&error::Error> { match *self { + #[cfg(feature = "online")] YubicoError::Network(ref err) => Some(err), + #[cfg(feature = "online")] YubicoError::HTTPStatusCode(_) => None, YubicoError::IOError(ref err) => Some(err), YubicoError::ChannelError(ref err) => Some(err), @@ -130,12 +140,14 @@ impl error::Error for YubicoError { } } +#[cfg(feature = "online")] impl From for YubicoError { fn from(err: reqwest::Error) -> YubicoError { YubicoError::Network(err) } } +#[cfg(feature = "online")] impl From for YubicoError { fn from(err: reqwest::StatusCode) -> YubicoError { YubicoError::HTTPStatusCode(err)