cargo fix, move to edition 2018

This commit is contained in:
J.C. Jones 2020-08-05 17:15:39 -07:00 коммит произвёл J.C. Jones
Родитель 9c65976d8a
Коммит df2d127278
11 изменённых файлов: 91 добавлений и 87 удалений

Просмотреть файл

@ -5,6 +5,7 @@ authors = ["J.C. Jones <jc@mozilla.com>", "Tim Taubert <ttaubert@mozilla.com>",
repository = "https://github.com/mozilla/authenticator-rs/"
license = "MPL-2.0"
description = "Library for interacting with CTAP1/2 security keys for Web Authentication. Used by Firefox."
edition = "2018"
[features]
binding-recompile = ["bindgen"]

Просмотреть файл

@ -7,15 +7,15 @@ use rand::{thread_rng, Rng};
use std::collections::HashMap;
use std::{ptr, slice};
use U2FManager;
use crate::U2FManager;
type U2FAppIds = Vec<::AppId>;
type U2FKeyHandles = Vec<::KeyHandle>;
type U2FAppIds = Vec<crate::AppId>;
type U2FKeyHandles = Vec<crate::KeyHandle>;
type U2FCallback = extern "C" fn(u64, *mut U2FResult);
pub enum U2FResult {
Success(HashMap<u8, Vec<u8>>),
Error(::Error),
Error(crate::Error),
}
const RESBUF_ID_REGISTRATION: u8 = 0;
@ -104,9 +104,9 @@ pub unsafe extern "C" fn rust_u2f_khs_add(
key_handle_len: usize,
transports: u8,
) {
(*khs).push(::KeyHandle {
(*khs).push(crate::KeyHandle {
credential: from_raw(key_handle_ptr, key_handle_len),
transports: ::AuthenticatorTransports::from_bits_truncate(transports),
transports: crate::AuthenticatorTransports::from_bits_truncate(transports),
});
}
@ -127,7 +127,7 @@ pub unsafe extern "C" fn rust_u2f_khs_free(khs: *mut U2FKeyHandles) {
#[no_mangle]
pub unsafe extern "C" fn rust_u2f_result_error(res: *const U2FResult) -> u8 {
if res.is_null() {
return ::Error::Unknown as u8;
return crate::Error::Unknown as u8;
}
if let U2FResult::Error(ref err) = *res {
@ -219,7 +219,7 @@ pub unsafe extern "C" fn rust_u2f_mgr_register(
return 0;
}
let flags = ::RegisterFlags::from_bits_truncate(flags);
let flags = crate::RegisterFlags::from_bits_truncate(flags);
let challenge = from_raw(challenge_ptr, challenge_len);
let application = from_raw(application_ptr, application_len);
let key_handles = (*khs).clone();
@ -280,7 +280,7 @@ pub unsafe extern "C" fn rust_u2f_mgr_sign(
return 0;
}
let flags = ::SignFlags::from_bits_truncate(flags);
let flags = crate::SignFlags::from_bits_truncate(flags);
let challenge = from_raw(challenge_ptr, challenge_len);
let app_ids = (*app_ids).clone();
let key_handles = (*khs).clone();

Просмотреть файл

@ -67,10 +67,10 @@ mod u2fprotocol;
mod u2ftypes;
mod manager;
pub use manager::U2FManager;
pub use crate::manager::U2FManager;
mod capi;
pub use capi::*;
pub use crate::capi::*;
// Keep this in sync with the constants in u2fhid-capi.h.
bitflags! {

Просмотреть файл

@ -4,15 +4,15 @@
extern crate log;
use consts::{CID_BROADCAST, MAX_HID_RPT_SIZE};
use crate::consts::{CID_BROADCAST, MAX_HID_RPT_SIZE};
use crate::platform::iokit::*;
use crate::u2ftypes::U2FDevice;
use core_foundation::base::*;
use platform::iokit::*;
use std::convert::TryInto;
use std::io;
use std::io::{Read, Write};
use std::sync::mpsc::{Receiver, RecvTimeoutError};
use std::time::Duration;
use u2ftypes::U2FDevice;
const READ_TIMEOUT: u64 = 15;

Просмотреть файл

@ -6,7 +6,7 @@
extern crate libc;
use consts::{FIDO_USAGE_PAGE, FIDO_USAGE_U2FHID};
use crate::consts::{FIDO_USAGE_PAGE, FIDO_USAGE_U2FHID};
use core_foundation::array::*;
use core_foundation::base::*;
use core_foundation::dictionary::*;

Просмотреть файл

@ -5,15 +5,15 @@
extern crate libc;
extern crate log;
use crate::platform::iokit::*;
use crate::util::io_err;
use core_foundation::base::*;
use core_foundation::runloop::*;
use platform::iokit::*;
use runloop::RunLoop;
use std::collections::HashMap;
use std::os::raw::c_void;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::{io, slice};
use util::io_err;
struct DeviceData {
tx: Sender<Vec<u8>>,

Просмотреть файл

@ -4,13 +4,13 @@
extern crate libc;
use crate::platform::iokit::{CFRunLoopEntryObserver, IOHIDDeviceRef, SendableRunLoop};
use crate::platform::monitor::Monitor;
use crate::util::StateCallback;
use core_foundation::runloop::*;
use platform::iokit::{CFRunLoopEntryObserver, IOHIDDeviceRef, SendableRunLoop};
use platform::monitor::Monitor;
use std::os::raw::c_void;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread;
use util::StateCallback;
// A transaction will run the given closure in a new thread, thereby using a
// separate per-thread state machine for each HID. It will either complete or
@ -24,9 +24,9 @@ pub struct Transaction {
impl Transaction {
pub fn new<F, T>(
timeout: u64,
callback: StateCallback<Result<T, ::Error>>,
callback: StateCallback<Result<T, crate::Error>>,
new_device_cb: F,
) -> Result<Self, ::Error>
) -> Result<Self, crate::Error>
where
F: Fn((IOHIDDeviceRef, Receiver<Vec<u8>>), &dyn Fn() -> bool) + Sync + Send + 'static,
T: 'static,
@ -47,7 +47,8 @@ impl Transaction {
// Create a new HID device monitor and start polling.
let mut monitor = Monitor::new(new_device_cb);
try_or!(monitor.start(), |_| callback.call(Err(::Error::Unknown)));
try_or!(monitor.start(), |_| callback
.call(Err(crate::Error::Unknown)));
// This will block until completion, abortion, or timeout.
unsafe { CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeout, 0) };
@ -56,12 +57,12 @@ impl Transaction {
monitor.stop();
// Send an error, if the callback wasn't called already.
callback.call(Err(::Error::NotAllowed));
callback.call(Err(crate::Error::NotAllowed));
})
.map_err(|_| ::Error::Unknown)?;
.map_err(|_| crate::Error::Unknown)?;
// Block until we enter the CFRunLoop.
let runloop = rx.recv().map_err(|_| ::Error::Unknown)?;
let runloop = rx.recv().map_err(|_| crate::Error::Unknown)?;
Ok(Self {
runloop: Some(runloop),

Просмотреть файл

@ -6,27 +6,27 @@ use std::io;
use std::sync::mpsc::{channel, RecvTimeoutError, Sender};
use std::time::Duration;
use consts::PARAMETER_SIZE;
use crate::consts::PARAMETER_SIZE;
use crate::statemachine::StateMachine;
use crate::util::StateCallback;
use runloop::RunLoop;
use statemachine::StateMachine;
use util::StateCallback;
enum QueueAction {
Register {
flags: ::RegisterFlags,
flags: crate::RegisterFlags,
timeout: u64,
challenge: Vec<u8>,
application: ::AppId,
key_handles: Vec<::KeyHandle>,
callback: StateCallback<Result<::RegisterResult, ::Error>>,
application: crate::AppId,
key_handles: Vec<crate::KeyHandle>,
callback: StateCallback<Result<crate::RegisterResult, crate::Error>>,
},
Sign {
flags: ::SignFlags,
flags: crate::SignFlags,
timeout: u64,
challenge: Vec<u8>,
app_ids: Vec<::AppId>,
key_handles: Vec<::KeyHandle>,
callback: StateCallback<Result<::SignResult, ::Error>>,
app_ids: Vec<crate::AppId>,
key_handles: Vec<crate::KeyHandle>,
callback: StateCallback<Result<crate::SignResult, crate::Error>>,
},
Cancel,
}
@ -96,24 +96,24 @@ impl U2FManager {
pub fn register<F>(
&self,
flags: ::RegisterFlags,
flags: crate::RegisterFlags,
timeout: u64,
challenge: Vec<u8>,
application: ::AppId,
key_handles: Vec<::KeyHandle>,
application: crate::AppId,
key_handles: Vec<crate::KeyHandle>,
callback: F,
) -> Result<(), ::Error>
) -> Result<(), crate::Error>
where
F: Fn(Result<::RegisterResult, ::Error>),
F: Fn(Result<crate::RegisterResult, crate::Error>),
F: Send + 'static,
{
if challenge.len() != PARAMETER_SIZE || application.len() != PARAMETER_SIZE {
return Err(::Error::Unknown);
return Err(crate::Error::Unknown);
}
for key_handle in &key_handles {
if key_handle.credential.len() > 256 {
return Err(::Error::Unknown);
return Err(crate::Error::Unknown);
}
}
@ -126,39 +126,39 @@ impl U2FManager {
key_handles,
callback,
};
self.tx.send(action).map_err(|_| ::Error::Unknown)
self.tx.send(action).map_err(|_| crate::Error::Unknown)
}
pub fn sign<F>(
&self,
flags: ::SignFlags,
flags: crate::SignFlags,
timeout: u64,
challenge: Vec<u8>,
app_ids: Vec<::AppId>,
key_handles: Vec<::KeyHandle>,
app_ids: Vec<crate::AppId>,
key_handles: Vec<crate::KeyHandle>,
callback: F,
) -> Result<(), ::Error>
) -> Result<(), crate::Error>
where
F: Fn(Result<::SignResult, ::Error>),
F: Fn(Result<crate::SignResult, crate::Error>),
F: Send + 'static,
{
if challenge.len() != PARAMETER_SIZE {
return Err(::Error::Unknown);
return Err(crate::Error::Unknown);
}
if app_ids.is_empty() {
return Err(::Error::Unknown);
return Err(crate::Error::Unknown);
}
for app_id in &app_ids {
if app_id.len() != PARAMETER_SIZE {
return Err(::Error::Unknown);
return Err(crate::Error::Unknown);
}
}
for key_handle in &key_handles {
if key_handle.credential.len() > 256 {
return Err(::Error::Unknown);
return Err(crate::Error::Unknown);
}
}
@ -171,13 +171,13 @@ impl U2FManager {
key_handles,
callback,
};
self.tx.send(action).map_err(|_| ::Error::Unknown)
self.tx.send(action).map_err(|_| crate::Error::Unknown)
}
pub fn cancel(&self) -> Result<(), ::Error> {
pub fn cancel(&self) -> Result<(), crate::Error> {
self.tx
.send(QueueAction::Cancel)
.map_err(|_| ::Error::Unknown)
.map_err(|_| crate::Error::Unknown)
}
}

Просмотреть файл

@ -2,25 +2,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use consts::PARAMETER_SIZE;
use platform::device::Device;
use platform::transaction::Transaction;
use crate::consts::PARAMETER_SIZE;
use crate::platform::device::Device;
use crate::platform::transaction::Transaction;
use crate::u2fprotocol::{u2f_init_device, u2f_is_keyhandle_valid, u2f_register, u2f_sign};
use crate::util::StateCallback;
use std::thread;
use std::time::Duration;
use u2fprotocol::{u2f_init_device, u2f_is_keyhandle_valid, u2f_register, u2f_sign};
use util::StateCallback;
fn is_valid_transport(transports: ::AuthenticatorTransports) -> bool {
transports.is_empty() || transports.contains(::AuthenticatorTransports::USB)
fn is_valid_transport(transports: crate::AuthenticatorTransports) -> bool {
transports.is_empty() || transports.contains(crate::AuthenticatorTransports::USB)
}
fn find_valid_key_handles<'a, F>(
app_ids: &'a [::AppId],
key_handles: &'a [::KeyHandle],
app_ids: &'a [crate::AppId],
key_handles: &'a [crate::KeyHandle],
mut is_valid: F,
) -> (&'a ::AppId, Vec<&'a ::KeyHandle>)
) -> (&'a crate::AppId, Vec<&'a crate::KeyHandle>)
where
F: FnMut(&Vec<u8>, &::KeyHandle) -> bool,
F: FnMut(&Vec<u8>, &crate::KeyHandle) -> bool,
{
// Try all given app_ids in order.
for app_id in app_ids {
@ -51,12 +51,12 @@ impl StateMachine {
pub fn register(
&mut self,
flags: ::RegisterFlags,
flags: crate::RegisterFlags,
timeout: u64,
challenge: Vec<u8>,
application: ::AppId,
key_handles: Vec<::KeyHandle>,
callback: StateCallback<Result<::RegisterResult, ::Error>>,
application: crate::AppId,
key_handles: Vec<crate::KeyHandle>,
callback: StateCallback<Result<crate::RegisterResult, crate::Error>>,
) {
// Abort any prior register/sign calls.
self.cancel();
@ -99,7 +99,7 @@ impl StateMachine {
if excluded {
let blank = vec![0u8; PARAMETER_SIZE];
if u2f_register(dev, &blank, &blank).is_ok() {
callback.call(Err(::Error::InvalidState));
callback.call(Err(crate::Error::InvalidState));
break;
}
} else if let Ok(bytes) = u2f_register(dev, &challenge, &application) {
@ -117,12 +117,12 @@ impl StateMachine {
pub fn sign(
&mut self,
flags: ::SignFlags,
flags: crate::SignFlags,
timeout: u64,
challenge: Vec<u8>,
app_ids: Vec<::AppId>,
key_handles: Vec<::KeyHandle>,
callback: StateCallback<Result<::SignResult, ::Error>>,
app_ids: Vec<crate::AppId>,
key_handles: Vec<crate::KeyHandle>,
callback: StateCallback<Result<crate::SignResult, crate::Error>>,
) {
// Abort any prior register/sign calls.
self.cancel();
@ -163,7 +163,9 @@ impl StateMachine {
// Aggregate distinct transports from all given credentials.
let transports = key_handles
.iter()
.fold(::AuthenticatorTransports::empty(), |t, k| t | k.transports);
.fold(crate::AuthenticatorTransports::empty(), |t, k| {
t | k.transports
});
// We currently only support USB. If the RP specifies transports
// and doesn't include USB it's probably lying.
@ -177,7 +179,7 @@ impl StateMachine {
if valid_handles.is_empty() {
let blank = vec![0u8; PARAMETER_SIZE];
if u2f_register(dev, &blank, &blank).is_ok() {
callback.call(Err(::Error::InvalidState));
callback.call(Err(crate::Error::InvalidState));
break;
}
} else {

Просмотреть файл

@ -11,9 +11,9 @@ use std::ffi::CString;
use std::io;
use std::io::{Read, Write};
use consts::*;
use u2ftypes::*;
use util::io_err;
use crate::consts::*;
use crate::u2ftypes::*;
use crate::util::io_err;
////////////////////////////////////////////////////////////////////////
// Device Commands
@ -217,14 +217,14 @@ mod tests {
use rand::{thread_rng, RngCore};
use super::{init_device, send_apdu, sendrecv, U2FDevice};
use consts::{CID_BROADCAST, SW_NO_ERROR, U2FHID_INIT, U2FHID_MSG, U2FHID_PING};
use crate::consts::{CID_BROADCAST, SW_NO_ERROR, U2FHID_INIT, U2FHID_MSG, U2FHID_PING};
mod platform {
use std::io;
use std::io::{Read, Write};
use consts::CID_BROADCAST;
use u2ftypes::U2FDevice;
use crate::consts::CID_BROADCAST;
use crate::u2ftypes::U2FDevice;
const IN_HID_RPT_SIZE: usize = 64;
const OUT_HID_RPT_SIZE: usize = 64;

Просмотреть файл

@ -4,8 +4,8 @@
use std::{cmp, io};
use consts::*;
use util::io_err;
use crate::consts::*;
use crate::util::io_err;
use log;