~ireas/nitrokey-rs

6039e0c76997014ed3f78768f8558da98d373e4b — Robin Krahl 4 months ago 3046af5
Make *Error, Model, DeviceWrapper non-exhaustive

Previously, all enums defined by the nitrokey crate were exhaustive.
This means that adding new variants to these enums is a breaking change.
To make it possible to add new features to nitrokey-rs without breaking
compatibility, this patch marks the Error, CommandError,
CommunicationError, LibraryError, Model and DeviceWrapper enums as
non-exhaustive.
4 files changed, 8 insertions(+), 0 deletions(-)

M CHANGELOG.md
M src/device/mod.rs
M src/device/wrapper.rs
M src/error.rs
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 5,6 5,8 @@ SPDX-License-Identifier: CC0-1.0

# Unreleased
- Export the `FirmwareVersion` struct.
- Mark the `Error`, `CommandError`, `CommunicationError`, `LibraryError`,
  `Model` and `DeviceWrapper` enums as non-exhaustive.

# v0.7.1 (2020-08-30)
- Remove the custom `std::error::Error::source` implementation for

M src/device/mod.rs => src/device/mod.rs +1 -0
@@ 28,6 28,7 @@ pub use wrapper::DeviceWrapper;

/// Available Nitrokey models.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum Model {
    /// The Nitrokey Storage.
    Storage,

M src/device/wrapper.rs => src/device/wrapper.rs +1 -0
@@ 64,6 64,7 @@ use crate::otp::GenerateOtp;
///
/// [`connect`]: struct.Manager.html#method.connect
#[derive(Debug)]
#[non_exhaustive]
pub enum DeviceWrapper<'a> {
    /// A Nitrokey Storage device.
    Storage(Storage<'a>),

M src/error.rs => src/error.rs +4 -0
@@ 11,6 11,7 @@ use crate::device;

/// An error returned by the nitrokey crate.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
    /// An error reported by the Nitrokey device in the response packet.
    CommandError(CommandError),


@@ 111,6 112,7 @@ impl fmt::Display for Error {

/// An error reported by the Nitrokey device in the response packet.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum CommandError {
    /// A packet with a wrong checksum has been sent or received.
    WrongCrc,


@@ 177,6 179,7 @@ impl fmt::Display for CommandError {

/// A device communication error.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum CommunicationError {
    /// Could not connect to a Nitrokey device.
    NotConnected,


@@ 215,6 218,7 @@ impl fmt::Display for CommunicationError {

/// A library usage error.
#[derive(Clone, Copy, Debug, PartialEq)]
#[non_exhaustive]
pub enum LibraryError {
    /// A supplied string exceeded a length limit.
    StringTooLong,