[][src]Struct nitrokey::SerialNumber

pub struct SerialNumber { /* fields omitted */ }

Serial number of a Nitrokey device.

The serial number can be formatted as a string using the ToString trait, and it can be parsed from a string using the FromStr trait. It can also be represented as a 32-bit unsigned integer using as_u32. This integer is the ID of the smartcard of the Nitrokey device.

Neither the format of the string representation nor the integer representation are guaranteed to stay the same for new firmware versions.

Methods

impl SerialNumber[src]

pub fn empty() -> Self[src]

Creates an emtpty serial number.

This function can be used to create a placeholder value or to compare a SerialNumber instance with an empty serial number.

pub fn as_u32(&self) -> u32[src]

Returns the integer reprensentation of this serial number.

This integer currently is the ID of the smartcard of the Nitrokey device. Upcoming firmware versions might change the meaning of this representation, or add additional components to the serial number.

Trait Implementations

impl Clone for SerialNumber[src]

impl Copy for SerialNumber[src]

impl Debug for SerialNumber[src]

impl Display for SerialNumber[src]

impl FromStr for SerialNumber[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<SerialNumber, Error>[src]

Try to parse a serial number from a hex string.

The input string must be a valid hex string. Optionally, it can include a 0x prefix.

Errors

Example

use std::convert::TryFrom;
use nitrokey::{DeviceInfo, Error, SerialNumber};

fn find_device(serial_number: &str) -> Result<Option<DeviceInfo>, Error> {
    let serial_number: SerialNumber = serial_number.parse()?;
    Ok(nitrokey::list_devices()?
        .into_iter()
        .filter(|device| device.serial_number == Some(serial_number))
        .next())
}

impl PartialEq<SerialNumber> for SerialNumber[src]

impl StructuralPartialEq for SerialNumber[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.