aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/error.rs
Commit message (Collapse)AuthorAge
* Implement From<&str> for ErrorRobin Krahl2019-01-26
| | | | | | This patch implements From<&str> for Error so that we can use Error::from(s) as a shorthand for Error::Error(s.to_string()). It also replaces Error::Error with Error::from where possible.
* Report command errors properlyDaniel Mueller2019-01-09
| | | | | | | | | | | | So far we have taken all nitrokey::CommandError objects and put them in formatted form into the Error::Error variant. What we really should do, though, is to preserve the original error, with the additional context provided by the caller, and report that up the stack directly. Doing so has at least the benefit that we are able to check for expected errors without hard coding the textual representation as maintained by the nitrokey create. This change refactors the code accordingly and adds two tests for such expected error codes.
* Make pinentry::inquire_pin return String directlyDaniel Mueller2019-01-09
| | | | | | | | | | | | | | | The inquire_pin function of the pinentry module used to return a vector of bytes, as that is what is ultimately read from the gpg-agent process. All clients of this function, however, work with a string and, hence, convert this vector into a string. As it turns out, for better or worse, the pinentry::parse_pinentry_pin function (which produces the result of inquire_pin) internally already works with a string but then converts it back. That is both not useful and a waste of resources. This change adjusts both functions of interest to simply return a String object instead, removing the need for conversions at the clients. While at it, the patch also removes the need for a bunch of unnecessary allocations caused by sub-par parameter type choice.
* Add first set of integration testsDaniel Mueller2019-01-05
| | | | | | | | | This change introduces the first set of integration-style test for the application. Those tests may or may not connect to an actual Nitrokey device (depending on what they test). We use the nitrokey-test crate's test attribute macro to automatically dispatch tests to connected devices or skip them if a required device is not present. It also provides the means for automatically serializing tests.
* Properly report io::Error objectsDaniel Mueller2019-01-06
| | | | | | | | | | We have a Result::unwrap in the error path of handling io::Error objects. I have actually seen that fail, masking the original error. We should not unwrap there and in fact we don't have to, as io::Error implements fmt::Display just fine. This may have changed in the past, as the construct we had is much more convoluted than necessary and would only have been written if a direct formatting was not possible.
* Port argument handling to argparseRobin Krahl2018-12-23
| | | | | | | | | This patch replaces the macro for argument parsing with `argparse::ArgumentParser` from the argparse crate. It moves the application logic to the `commands` module and the argument parsing to the `options` module. An enum is used to represent the available commands. The code is based on the `subcommands.rs` example shipped with argparse.
* Make code conforming to rustfmt's expectationsDaniel Mueller2018-12-17
| | | | | | | | | | | | | | An automated code formatter can help tremendously in reducing the amount of cognitive energy wasted on thinking about the "best" formatting of code as well as the number of nitpicks reviews typically get -- the format is machine checked (and enforced) and there is usually little to no discussion about the validity. To reach the goal of having such automated enforcement, we want to run the rustfmt tool as part of the CI pipeline. With rustfmt having reached 1.0 recently, the believe is that by now the formatting is reasonably stable and usable for this purpose. In that light, this change formats the code using rustfmt and prepares for such an automated style check.
* Remove unused dependenciesRobin Krahl2018-12-17
| | | | | | | | | This patch removes all dependencies that are no longer required since the hidapi communication is replaced by libnitrokey. Delete subrepo hid/:hid Delete subrepo hidapi-sys/:hidapi-sys Delete subrepo pkg-config/:pkg-config
* Port the status command to libnitrokeyRobin Krahl2018-12-17
| | | | | | This patch removes the raw hidapi implementation of the status command and all utility methods that are no longer needed. With this patch, all device communication is performed using libnitrokey.
* Compile program with 2018 Edition of RustDaniel Mueller2018-12-11
| | | | | | | With the 1.31 release of Rust support for Edition 2018 has reached the stable tool chain. This change enables compilation based off of this new edition for the crate. This change resolves issue #6.
* Make hidden lifetime parameters explicitDaniel Mueller2018-12-10
| | | | | | | | | | | | | With a recent Rust version upgrade hidden lifetime parameters cause a warning of the form: > warning: hidden lifetime parameters in types are deprecated > --> src/error.rs:58:25 > | > 58 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { > | ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>` This change adjusts the code to make those lifetimes explicit (while keeping them anonymous).
* Enable rust_2018_compatibility lintDaniel Mueller2018-12-10
| | | | | | | | In preparation for the switch to using Rust 2018, this change enables the rust_2018_compatibility lint. Along with that enablement we fix the warnings emitted by it, which evolve around the module system changes Rust has gone through and that require us to prefix initial uses of crate local modules with "crate".
* Fix issues reported by clippyDaniel Mueller2018-02-18
| | | | | The clippy tool has a couple of suggestions on how to improve the code. This change applies them to the project's code base.
* Add pinentry moduleDaniel Mueller2017-03-27
| | | | | | | | | | | | | | | | We do not want to roll our own infrastructure for entering a password (or PIN) securely, as there are existing providers of such functionality. gpg-agent, which uses pinentry for this very purpose, is such a program and we can safely assume to be present because we use it with the smartcard part of the nitrokey. This change introduces a new module, pinentry.rs, that provides the means to invoke gpg-agent to ask the user for a PIN and to parse the result. Using gpg-agent like this has two advantages that other solutions do not necessarily provide: first, because we use gpg-agent anyway it's pinentry configuration is as the user desires it and, hence, the integration appears seamless. And second, the agent caches pass phrases which alleviates the need for repeated entry should the credential be required again.
* Discover and open nictrokey using libhidapiDaniel Mueller2017-03-26
This change uses the 'hid' crate to discover and open the Nitrokey Storage device. 'hid' is a wrapper around libhidapi (its libusb back-end in particular). Being a command line application some sort of parameter handling needs to happen. The approach we take is very simple for now to minimize the number of dependencies: we just compare the first argument against the expected ones and raise an error if no match was found. Because we only have positional arguments right now this is all we need.