summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAge
* Remove the static lifetime modifier from constantsRobin Krahl2019-01-27
| | | | | The DEFAULT_{ADMIN,USER}_PIN constants implicitly have static lifetime. Therefore we can remove the static lifetime modifiers.
* Rename Error::Unknown to Error::UnknownErrorRobin Krahl2019-01-27
| | | | | For consistency with the other Error variants, we rename Unknown to UnknownError.
* Remove the Result typedefRobin Krahl2019-01-27
| | | | | | | | | Many of our functions do not return a Result<_, Error>, but for example a Result<_, (Device, Error)>. We only use the typedef in one function, but it makes the other functions more complicated as we have to use result::Result (if crate::Result is imported). Therefore, this patch removes the typedef. Applications or libraries can still redefine it if they want to.
* Remove rand_core::Error from public APIRobin Krahl2019-01-25
| | | | | | | rand_core does not have a stable release yet, and it is unlikely that there will be one soon. To be able to stabilize nitrokey without waiting for a stable rand_core version, we remove the rand_core::Error type from the public API and replace it with a Box<dyn error::Error>.
* Add license and copyright informationRobin Krahl2019-01-23
| | | | | | | This patch adds license and copyright information to all files to make nitrokey-rs compliant with the REUSE practices [0]. [0] https://reuse.software/practices/2.0/
* Implement From<(T: Device, Error)> for ErrorRobin Krahl2019-01-23
| | | | | | Not all users of the authenticate methods want to use the device after an error, so implementing From<(T: Device, Error)> for Error makes it easier for them to discard the device.
* Return UTF-8 error if libnitrokey returns an invalid stringRobin Krahl2019-01-23
| | | | | | | Previously, we used lossy UTF-8 conversion. Yet the user should be notified if we have a problem instead of silently changing the data. Therefore, we now return an error if we enocunter an invalid UTF-8 string. This leads to a change in `get_library_version`’s signature.
* Add Error::Utf8Error variantRobin Krahl2019-01-23
| | | | | Previously, we just ignored UTF-8 errors. This patch prepares the Utf8Error variant so that we are able to return UTF-8 errors.
* Implement From<Pro> and From<Storage> for DeviceWrapperRobin Krahl2019-01-23
|
* Add Pro::new and Storage::new functionsRobin Krahl2019-01-23
|
* Refactor and clean up all codeRobin Krahl2019-01-23
| | | | | | | This includes: - using idiomatic Rust - limiting the scope of unsafe blocks - simplifying code
* Add temp_password_ptr method to AuthenticatedDeviceRobin Krahl2019-01-23
| | | | | | To reduce the number of casts, we introduce the temp_password_ptr method that casts the pointer received from the Vec<u8> to a c_char pointer that can be handled by libnitrokey.
* Prefer into() over numeric castingRobin Krahl2019-01-23
| | | | | | Numeric casting might truncate an integer, while into() is only implemented for numeric types if the cast is possible without truncation.
* Prevent direct instantiation of Pro and StorageRobin Krahl2019-01-23
| | | | | | The Pro and Storage structs may only be created using the connect functions. This patch adds a private PhantomData field to the structs to ensure that the compiler does not allow direct instantiation.
* Check specific error codes in the testsRobin Krahl2019-01-20
| | | | | | | | | | If possible, check specific error codes instead of `is_err()`. This makes the code more readable and catches bugs resulting in the wrong error code. Also, using the assert_*_err and assert_ok macros yields error messages containing the expected and the actual value. To be able to use these macros with the `get_password_safe` method, we also have to implement `Debug` for `PasswordSafe` and `Device`.
* Remove the unused CommandError::Undefined variantRobin Krahl2019-01-20
| | | | | | The CommandError::Undefined variant has been refactored into Error::UnexpectedError and CommunicationError::NotConnected and is therefore no longer needed.
* Return CommunicationError::NotConnected from connect functionsRobin Krahl2019-01-20
| | | | | | | | | Previously, we returned a CommandError::Undefined if a connect function failed. A CommunicationError::NotConnected is a more specific and better fitting choice. Once the Try trait has been stabilized, we should return an Option<_> instead of a Result<_, Error> from the connect functions.
* Introduce the Error::UnexpectedError variantRobin Krahl2019-01-20
| | | | | | | The UnexpectedError variant is used when a libnitrokey function returns a value that violates the function’s contract, for example if a function returns a null pointer although it guarantees to never return null. Previously, we returned a CommandError::Unspecified in these cases.
* Make CommandError messages more generalRobin Krahl2019-01-20
| | | | For example, the WrongSlot error may also be returned for a PWS slot.
* Remove CommandError::as_str methodRobin Krahl2019-01-20
| | | | | AsStr is automatically implementeded if Display is implemented, so having a manual as_str() method is not necessary.
* Add the CommunicationError enumRobin Krahl2019-01-20
| | | | | | Communication errors returned by libnitrokey were previously not mapped to an error type in the nitrokey crate. We introduce the CommunicationError enum to represent these errors.
* Refactor library errors into LibraryError enumRobin Krahl2019-01-20
| | | | | | Previously, library errors were part of the CommandError enum. As command errors and library errors are two different error types, they should be split into two enums.
* Move the CommandError::Unknown to ErrorRobin Krahl2019-01-20
| | | | | | | An error code can not only indiciate a command error, but also a library or device communication error. Therefore, the variant for an unknown error code should be placed in the top-level Error enum instead of the CommandError enum.
* Refactor CommandError::RngError into Error::RandErrorRobin Krahl2019-01-20
| | | | | We reserve CommandError for errors returned by the Nitrokey device. Errors during random number generation should have their own type.
* Return Error instead of CommandErrorRobin Krahl2019-01-20
| | | | | | | | | | This patch changes all public functions to return the Error enum instead of the CommandError enum. This breaks the tests which will be fixed with the next patch. This patch also adds a placeholder variant Error::CommandError and a placeholder enum CommandError to make the transition to a new nitrokey-test version easier.
* Add the Error enum and the Result<T> typedefRobin Krahl2019-01-20
| | | | | The Error enum is a wrapper for the possible error types (currently only CommandError). Result<T> is defined as Result<T, Error>.
* Implement std::error::Error for error::CommandErrorRobin Krahl2019-01-20
|
* Move util::CommandError to the new error moduleRobin Krahl2019-01-20
| | | | This prepares the refactoring of util::CommandError into multiple enums.
* Merge branch 'hotfix-0.3.4' into nextRobin Krahl2019-01-20
|\
| * Pass temporary password as *const c_charRobin Krahl2019-01-20
| | | | | | | | | | | | | | | | | | The random number generator used for the temporary password produces a Vec<u8>. The libnitrokey functions using the temporary password require a pointer to a c_char. Previously, we cast the u8 pointer to the Vec<u8> to a i8 pointer (unsigned to signed). This leads to a type mismatch if the char type is not signed. Therefore we now cast to c_char instead of i8.
* | Introduce DEFAULT_ADMIN_PIN and DEFAULT_USER_PIN constantsRobin Krahl2019-01-19
| | | | | | | | The constants can be used for tests or after a factory reset.
* | Implement Display for VersionRobin Krahl2019-01-17
| |
* | Introduce the FirmwareVersion structRobin Krahl2019-01-17
|/ | | | | | The FirmwareVersion struct stores the major and minor firmware version of a Nitrokey device. We refactor the StorageProductionInfo and StorageStatus structs to use this new struct.
* Document and test empty Git versionsRobin Krahl2019-01-16
| | | | | If libnitrokey has not been built from a clone of the Git repository, the Git version string may be empty.
* pws: Interpret empty strings as unprogrammed slotsRobin Krahl2019-01-16
| | | | | | | | | | | | Until the last commit, all empty strings returned by the library were interepreted as errors. As the PWS functions return empty strings for unprogrammed slots, the methods to access the PWS data returned an error when querying a slot that is not programmed. Since the last commit, they return an empty string instead. This patch restores the old behavior by returning an error instead of an empty string. Yet we change the error variant: SlotNotProgrammed instead of Undefined.
* Fix result_from_string for empty return valuesRobin Krahl2019-01-16
| | | | | | | | | | | An empty string returned from a libnitrokey function can either indicate an error or be a valid return value. Previously, we assumed that it indicates an error. But instead, we should check the last command status and use it to decide whether to return the empty string or an error code. This breaks the unit tests that assume that empty strings cause errors. These will be fixed in the next patches.
* Fix typo: destory -> destroyDaniel Mueller2019-01-16
|
* Use rand_os for random data generationDaniel Mueller2019-01-14
| | | | | | | | | | | | The rand crate comes with a slew of dependencies to cover all sort of randomness related tasks in various scenarios. However, this crate really only requires a tiny subset of this functionality. As it turns out, this core functionality is provided by the rand_os crate. This change drops the dependency to rand in favor of rand_os. In order to accomplish that, it brings back the RngError variant for the CommandError enum to capture the possibility of the creation of the random number generator failing.
* Add the clear_new_sd_card_warning method to StorageRobin Krahl2019-01-14
| | | | | | The clear_new_sd_card_warning method calls the libnitrokey NK_clear_new_sd_card_warning function to reset the corresponding flag in the Storage status.
* Add the get_production_info method to the Storage structRobin Krahl2019-01-14
| | | | | | | | | | | The get_production_info method maps to the NK_get_production_info function of libnitrokey. The Storage firmware supports two query modes: with or without a write test. libnitrokey only performs the query without write test, so the fields that are only set for the write test are ignored in our implementation. This affects: - user and admin retry counts - smart card ID - SD card size
* Add export_firmware method to StorageRobin Krahl2019-01-12
| | | | | | | The export_firmware method writes the firmware of the Nitrokey Storage to the unencrypted storage. We only test that the command succeeds as mounting the unencrypted storage and accessing the file is out of scope for the tests.
* Add set_unencrypted_volume_mode to StorageRobin Krahl2019-01-12
| | | | | | | | | | The new set_unencrypted_volume_mode method sets the access mode of the unencrypted volume on the Nitrokey Storage. Depending on the requested access mode, it calls either NK_set_unencrypted_read_only_admin or NK_set_unencrypted_read_write_admin. Note that this function requires firmware version 0.51 or later. (Earlier firmware versions used the user PIN.)
* Introduce VolumeMode enum in deviceRobin Krahl2019-01-12
| | | | | | The VolumeMode enum will be used when setting the access mode for the unencrypted volume. It can also be used when refactoring the VolumeStatus enum in a future release.
* Fix formatting in get_library_versionRobin Krahl2019-01-12
|
* Add the wink method to the Storage structRobin Krahl2019-01-11
| | | | | | This patch adds the wink method to the Storage struct that lets the Nitrokey device blink until reconnected. We do not test this method as it does not change the state that we can observe.
* Add the get_library_version functionRobin Krahl2019-01-11
| | | | | | | This patch adds the get_library_version function to the main library module that queries and returns the libnitrokey version. As the version fields are static values, we fetch them all at the same time and do not provide getters for the individual fields.
* Make three more error codes knownDaniel Mueller2019-01-09
| | | | | | | | | | | | | Three more error codes are defined in libnitrokey but currently reported as the CommandError::Unknown variant: 200: representing a string that exceeds a limit 202: indicating a string that is not in hexadecimal format when it should be 203: suggesting that the target buffer is smaller than the source buffer and, hence, too small This change introduces the CommandError variants StringTooLong, InvalidHexString and TargetBufferTooSmall, respectively, representing those errors.
* Add the connect_model functionRobin Krahl2019-01-07
| | | | | | This patch adds the global connect_model function that can be used to connect to a Nitrokey device of a given model. Contrary to Pro::connect and Storage::connect, the model does not have to be set at compile time.
* Rename device::connect_model to device::connect_enumRobin Krahl2019-01-07
| | | | connect_model will be used for a public function with the next patch.
* Document the Undefined error for the connect methodsRobin Krahl2019-01-07
|