From d0d9683df8398696147e7ee1fcffb2e4e957008c Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sat, 4 Apr 2020 14:39:19 -0700 Subject: Remove vendored dependencies While it appears that by now we actually can get successful builds without Cargo insisting on Internet access by virtue of using the --frozen flag, maintaining vendored dependencies is somewhat of a pain point. This state will also get worse with upcoming changes that replace argparse in favor of structopt and pull in a slew of new dependencies by doing so. Then there is also the repository structure aspect, which is non-standard due to the way we vendor dependencies and a potential source of confusion. In order to fix these problems, this change removes all the vendored dependencies we have. Delete subrepo argparse/:argparse Delete subrepo base32/:base32 Delete subrepo cc/:cc Delete subrepo cfg-if/:cfg-if Delete subrepo getrandom/:getrandom Delete subrepo lazy-static/:lazy-static Delete subrepo libc/:libc Delete subrepo nitrokey-sys/:nitrokey-sys Delete subrepo nitrokey/:nitrokey Delete subrepo rand/:rand --- nitrokey/src/util.rs | 99 ---------------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100644 nitrokey/src/util.rs (limited to 'nitrokey/src/util.rs') diff --git a/nitrokey/src/util.rs b/nitrokey/src/util.rs deleted file mode 100644 index 5a56c55..0000000 --- a/nitrokey/src/util.rs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (C) 2018-2019 Robin Krahl -// SPDX-License-Identifier: MIT - -use std::ffi::{CStr, CString}; -use std::os::raw::{c_char, c_int}; - -use libc::{c_void, free}; -use rand_core::{OsRng, RngCore}; - -use crate::error::{Error, LibraryError}; - -/// Log level for libnitrokey. -/// -/// Setting the log level to a lower level enables all output from higher levels too. Currently, -/// only the log levels `Warning`, `DebugL1`, `Debug` and `DebugL2` are actually used. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum LogLevel { - /// Error messages. Currently not used. - Error, - /// Warning messages. - Warning, - /// Informational messages. Currently not used. - Info, - /// Basic debug messages, especially basic information on the sent and received packets. - DebugL1, - /// Detailed debug messages, especially detailed information on the sent and received packets. - Debug, - /// Very detailed debug messages, especially detailed information about the control flow for - /// device communication (for example function entries and exits). - DebugL2, -} - -pub fn owned_str_from_ptr(ptr: *const c_char) -> Result { - unsafe { CStr::from_ptr(ptr) } - .to_str() - .map(String::from) - .map_err(Error::from) -} - -pub fn result_from_string(ptr: *const c_char) -> Result { - if ptr.is_null() { - return Err(Error::UnexpectedError); - } - let s = owned_str_from_ptr(ptr)?; - unsafe { free(ptr as *mut c_void) }; - // An empty string can both indicate an error or be a valid return value. In this case, we - // have to check the last command status to decide what to return. - if s.is_empty() { - get_last_result().map(|_| s) - } else { - Ok(s) - } -} - -pub fn result_or_error(value: T) -> Result { - get_last_result().and(Ok(value)) -} - -pub fn get_command_result(value: c_int) -> Result<(), Error> { - if value == 0 { - Ok(()) - } else { - Err(Error::from(value)) - } -} - -pub fn get_last_result() -> Result<(), Error> { - get_command_result(unsafe { nitrokey_sys::NK_get_last_command_status() }.into()) -} - -pub fn get_last_error() -> Error { - match get_last_result() { - Ok(()) => Error::UnexpectedError, - Err(err) => err, - } -} - -pub fn generate_password(length: usize) -> Result, Error> { - let mut data = vec![0u8; length]; - OsRng.fill_bytes(&mut data[..]); - Ok(data) -} - -pub fn get_cstring>>(s: T) -> Result { - CString::new(s).or_else(|_| Err(LibraryError::InvalidString.into())) -} - -impl Into for LogLevel { - fn into(self) -> i32 { - match self { - LogLevel::Error => 0, - LogLevel::Warning => 1, - LogLevel::Info => 2, - LogLevel::DebugL1 => 3, - LogLevel::Debug => 4, - LogLevel::DebugL2 => 5, - } - } -} -- cgit v1.2.1