Move enums and add UsbPid.

This commit is contained in:
Dain Nilsson 2022-03-16 12:43:56 +01:00
parent 484adac9df
commit 22a4827616
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
11 changed files with 659 additions and 542 deletions

View File

@ -32,7 +32,11 @@ class _YubikeyProvider extends StateNotifier<YubiKeyData?> {
DeviceNode deviceNode = isNfc
? DeviceNode.nfcReader(DevicePath([]), name)
: DeviceNode.usbYubiKey(DevicePath([]), name, -1, deviceInfo);
: DeviceNode.usbYubiKey(
DevicePath([]),
name,
/*TODO: replace with correct PID*/ UsbPid.yk4OtpFidoCcid,
deviceInfo);
state = YubiKeyData(deviceNode, name, deviceInfo);
} on Exception catch (e) {
_log.config('Invalid data for yubikey: $input. $e');

View File

@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../management/models.dart';
import '../core/models.dart';
part 'models.freezed.dart';
const _listEquality = ListEquality();
enum Availability { enabled, disabled, unsupported }
enum Application { oath, fido, otp, piv, openpgp, hsmauth, management }
@ -71,14 +74,19 @@ extension Applications on Application {
}
}
@freezed
class ApplicationStateResult<T> with _$ApplicationStateResult {
factory ApplicationStateResult.none() = _None;
factory ApplicationStateResult.failure(String reason) = _Failure;
factory ApplicationStateResult.success(T state) = _Success;
}
@freezed
class YubiKeyData with _$YubiKeyData {
factory YubiKeyData(DeviceNode node, String name, DeviceInfo info) =
_YubiKeyData;
}
const _listEquality = ListEquality();
class DevicePath {
final List<String> segments;
@ -96,7 +104,8 @@ class DevicePath {
class DeviceNode with _$DeviceNode {
const DeviceNode._();
factory DeviceNode.usbYubiKey(
DevicePath path, String name, int pid, DeviceInfo? info) = UsbYubiKeyNode;
DevicePath path, String name, UsbPid pid, DeviceInfo? info) =
UsbYubiKeyNode;
factory DeviceNode.nfcReader(DevicePath path, String name) = NfcReaderNode;
Transport get transport =>

View File

@ -13,6 +13,482 @@ T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
class _$ApplicationStateResultTearOff {
const _$ApplicationStateResultTearOff();
_None<T> none<T>() {
return _None<T>();
}
_Failure<T> failure<T>(String reason) {
return _Failure<T>(
reason,
);
}
_Success<T> success<T>(T state) {
return _Success<T>(
state,
);
}
}
/// @nodoc
const $ApplicationStateResult = _$ApplicationStateResultTearOff();
/// @nodoc
mixin _$ApplicationStateResult<T> {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ApplicationStateResultCopyWith<T, $Res> {
factory $ApplicationStateResultCopyWith(ApplicationStateResult<T> value,
$Res Function(ApplicationStateResult<T>) then) =
_$ApplicationStateResultCopyWithImpl<T, $Res>;
}
/// @nodoc
class _$ApplicationStateResultCopyWithImpl<T, $Res>
implements $ApplicationStateResultCopyWith<T, $Res> {
_$ApplicationStateResultCopyWithImpl(this._value, this._then);
final ApplicationStateResult<T> _value;
// ignore: unused_field
final $Res Function(ApplicationStateResult<T>) _then;
}
/// @nodoc
abstract class _$NoneCopyWith<T, $Res> {
factory _$NoneCopyWith(_None<T> value, $Res Function(_None<T>) then) =
__$NoneCopyWithImpl<T, $Res>;
}
/// @nodoc
class __$NoneCopyWithImpl<T, $Res>
extends _$ApplicationStateResultCopyWithImpl<T, $Res>
implements _$NoneCopyWith<T, $Res> {
__$NoneCopyWithImpl(_None<T> _value, $Res Function(_None<T>) _then)
: super(_value, (v) => _then(v as _None<T>));
@override
_None<T> get _value => super._value as _None<T>;
}
/// @nodoc
class _$_None<T> implements _None<T> {
_$_None();
@override
String toString() {
return 'ApplicationStateResult<$T>.none()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _None<T>);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) {
return none();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) {
return none?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) {
if (none != null) {
return none();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) {
return none(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) {
return none?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) {
if (none != null) {
return none(this);
}
return orElse();
}
}
abstract class _None<T> implements ApplicationStateResult<T> {
factory _None() = _$_None<T>;
}
/// @nodoc
abstract class _$FailureCopyWith<T, $Res> {
factory _$FailureCopyWith(
_Failure<T> value, $Res Function(_Failure<T>) then) =
__$FailureCopyWithImpl<T, $Res>;
$Res call({String reason});
}
/// @nodoc
class __$FailureCopyWithImpl<T, $Res>
extends _$ApplicationStateResultCopyWithImpl<T, $Res>
implements _$FailureCopyWith<T, $Res> {
__$FailureCopyWithImpl(_Failure<T> _value, $Res Function(_Failure<T>) _then)
: super(_value, (v) => _then(v as _Failure<T>));
@override
_Failure<T> get _value => super._value as _Failure<T>;
@override
$Res call({
Object? reason = freezed,
}) {
return _then(_Failure<T>(
reason == freezed
? _value.reason
: reason // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$_Failure<T> implements _Failure<T> {
_$_Failure(this.reason);
@override
final String reason;
@override
String toString() {
return 'ApplicationStateResult<$T>.failure(reason: $reason)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _Failure<T> &&
const DeepCollectionEquality().equals(other.reason, reason));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(reason));
@JsonKey(ignore: true)
@override
_$FailureCopyWith<T, _Failure<T>> get copyWith =>
__$FailureCopyWithImpl<T, _Failure<T>>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) {
return failure(reason);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) {
return failure?.call(reason);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) {
if (failure != null) {
return failure(reason);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) {
return failure(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) {
return failure?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) {
if (failure != null) {
return failure(this);
}
return orElse();
}
}
abstract class _Failure<T> implements ApplicationStateResult<T> {
factory _Failure(String reason) = _$_Failure<T>;
String get reason;
@JsonKey(ignore: true)
_$FailureCopyWith<T, _Failure<T>> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$SuccessCopyWith<T, $Res> {
factory _$SuccessCopyWith(
_Success<T> value, $Res Function(_Success<T>) then) =
__$SuccessCopyWithImpl<T, $Res>;
$Res call({T state});
}
/// @nodoc
class __$SuccessCopyWithImpl<T, $Res>
extends _$ApplicationStateResultCopyWithImpl<T, $Res>
implements _$SuccessCopyWith<T, $Res> {
__$SuccessCopyWithImpl(_Success<T> _value, $Res Function(_Success<T>) _then)
: super(_value, (v) => _then(v as _Success<T>));
@override
_Success<T> get _value => super._value as _Success<T>;
@override
$Res call({
Object? state = freezed,
}) {
return _then(_Success<T>(
state == freezed
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as T,
));
}
}
/// @nodoc
class _$_Success<T> implements _Success<T> {
_$_Success(this.state);
@override
final T state;
@override
String toString() {
return 'ApplicationStateResult<$T>.success(state: $state)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _Success<T> &&
const DeepCollectionEquality().equals(other.state, state));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(state));
@JsonKey(ignore: true)
@override
_$SuccessCopyWith<T, _Success<T>> get copyWith =>
__$SuccessCopyWithImpl<T, _Success<T>>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) {
return success(state);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) {
return success?.call(state);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(state);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) {
return success(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) {
return success?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(this);
}
return orElse();
}
}
abstract class _Success<T> implements ApplicationStateResult<T> {
factory _Success(T state) = _$_Success<T>;
T get state;
@JsonKey(ignore: true)
_$SuccessCopyWith<T, _Success<T>> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
class _$YubiKeyDataTearOff {
const _$YubiKeyDataTearOff();
@ -205,7 +681,7 @@ class _$DeviceNodeTearOff {
const _$DeviceNodeTearOff();
UsbYubiKeyNode usbYubiKey(
DevicePath path, String name, int pid, DeviceInfo? info) {
DevicePath path, String name, UsbPid pid, DeviceInfo? info) {
return UsbYubiKeyNode(
path,
name,
@ -233,21 +709,23 @@ mixin _$DeviceNode {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
DevicePath path, String name, int pid, DeviceInfo? info)
DevicePath path, String name, UsbPid pid, DeviceInfo? info)
usbYubiKey,
required TResult Function(DevicePath path, String name) nfcReader,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function(DevicePath path, String name, int pid, DeviceInfo? info)?
TResult Function(
DevicePath path, String name, UsbPid pid, DeviceInfo? info)?
usbYubiKey,
TResult Function(DevicePath path, String name)? nfcReader,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DevicePath path, String name, int pid, DeviceInfo? info)?
TResult Function(
DevicePath path, String name, UsbPid pid, DeviceInfo? info)?
usbYubiKey,
TResult Function(DevicePath path, String name)? nfcReader,
required TResult orElse(),
@ -319,7 +797,7 @@ abstract class $UsbYubiKeyNodeCopyWith<$Res>
UsbYubiKeyNode value, $Res Function(UsbYubiKeyNode) then) =
_$UsbYubiKeyNodeCopyWithImpl<$Res>;
@override
$Res call({DevicePath path, String name, int pid, DeviceInfo? info});
$Res call({DevicePath path, String name, UsbPid pid, DeviceInfo? info});
$DeviceInfoCopyWith<$Res>? get info;
}
@ -353,7 +831,7 @@ class _$UsbYubiKeyNodeCopyWithImpl<$Res> extends _$DeviceNodeCopyWithImpl<$Res>
pid == freezed
? _value.pid
: pid // ignore: cast_nullable_to_non_nullable
as int,
as UsbPid,
info == freezed
? _value.info
: info // ignore: cast_nullable_to_non_nullable
@ -383,7 +861,7 @@ class _$UsbYubiKeyNode extends UsbYubiKeyNode {
@override
final String name;
@override
final int pid;
final UsbPid pid;
@override
final DeviceInfo? info;
@ -420,7 +898,7 @@ class _$UsbYubiKeyNode extends UsbYubiKeyNode {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
DevicePath path, String name, int pid, DeviceInfo? info)
DevicePath path, String name, UsbPid pid, DeviceInfo? info)
usbYubiKey,
required TResult Function(DevicePath path, String name) nfcReader,
}) {
@ -430,7 +908,8 @@ class _$UsbYubiKeyNode extends UsbYubiKeyNode {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function(DevicePath path, String name, int pid, DeviceInfo? info)?
TResult Function(
DevicePath path, String name, UsbPid pid, DeviceInfo? info)?
usbYubiKey,
TResult Function(DevicePath path, String name)? nfcReader,
}) {
@ -440,7 +919,8 @@ class _$UsbYubiKeyNode extends UsbYubiKeyNode {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DevicePath path, String name, int pid, DeviceInfo? info)?
TResult Function(
DevicePath path, String name, UsbPid pid, DeviceInfo? info)?
usbYubiKey,
TResult Function(DevicePath path, String name)? nfcReader,
required TResult orElse(),
@ -485,7 +965,7 @@ class _$UsbYubiKeyNode extends UsbYubiKeyNode {
abstract class UsbYubiKeyNode extends DeviceNode {
factory UsbYubiKeyNode(
DevicePath path, String name, int pid, DeviceInfo? info) =
DevicePath path, String name, UsbPid pid, DeviceInfo? info) =
_$UsbYubiKeyNode;
UsbYubiKeyNode._() : super._();
@ -493,7 +973,7 @@ abstract class UsbYubiKeyNode extends DeviceNode {
DevicePath get path;
@override
String get name;
int get pid;
UsbPid get pid;
DeviceInfo? get info;
@override
@JsonKey(ignore: true)
@ -578,7 +1058,7 @@ class _$NfcReaderNode extends NfcReaderNode {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
DevicePath path, String name, int pid, DeviceInfo? info)
DevicePath path, String name, UsbPid pid, DeviceInfo? info)
usbYubiKey,
required TResult Function(DevicePath path, String name) nfcReader,
}) {
@ -588,7 +1068,8 @@ class _$NfcReaderNode extends NfcReaderNode {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function(DevicePath path, String name, int pid, DeviceInfo? info)?
TResult Function(
DevicePath path, String name, UsbPid pid, DeviceInfo? info)?
usbYubiKey,
TResult Function(DevicePath path, String name)? nfcReader,
}) {
@ -598,7 +1079,8 @@ class _$NfcReaderNode extends NfcReaderNode {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(DevicePath path, String name, int pid, DeviceInfo? info)?
TResult Function(
DevicePath path, String name, UsbPid pid, DeviceInfo? info)?
usbYubiKey,
TResult Function(DevicePath path, String name)? nfcReader,
required TResult orElse(),

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import '../../core/models.dart';
import '../../management/models.dart';
const _imagesForName = {

View File

@ -1,6 +1,117 @@
import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../management/models.dart';
part 'models.freezed.dart';
part 'models.g.dart';
enum Transport { usb, nfc }
enum UsbInterface { otp, fido, ccid }
@JsonEnum(alwaysCreate: true)
enum UsbPid {
@JsonValue(0x0010)
yksOtp,
@JsonValue(0x0110)
neoOtp,
@JsonValue(0x0111)
neoOtpCcid,
@JsonValue(0x0112)
neoCcid,
@JsonValue(0x0113)
neoFido,
@JsonValue(0x0114)
neoOtpFido,
@JsonValue(0x0115)
neoFidoCcid,
@JsonValue(0x0116)
neoOtpFidoCcid,
@JsonValue(0x0120)
skyFido,
@JsonValue(0x0401)
yk4Otp,
@JsonValue(0x0402)
yk4Fido,
@JsonValue(0x0403)
yk4OtpFido,
@JsonValue(0x0404)
yk4Ccid,
@JsonValue(0x0405)
yk4OtpCcid,
@JsonValue(0x0406)
yk4FidoCcid,
@JsonValue(0x0407)
yk4OtpFidoCcid,
@JsonValue(0x0410)
ykpOtpFido,
}
extension UsbPids on UsbPid {
int get value => _$UsbPidEnumMap[this]!;
String get displayName {
switch (this) {
case UsbPid.yksOtp:
return 'YubiKey Standard';
case UsbPid.ykpOtpFido:
return 'YubiKey Plus';
case UsbPid.skyFido:
return 'Security Key by Yubico';
default:
final prefix = name.startsWith('neo') ? 'YubiKey NEO' : 'YubiKey';
final suffix = UsbInterface.values
.where((e) => e.value & usbInterfaces != 0)
.map((e) => e.name.toUpperCase())
.join(' ');
return '$prefix $suffix';
}
}
int get usbInterfaces => UsbInterface.values
.where(
(e) => name.contains(e.name[0].toUpperCase() + e.name.substring(1)))
.map((e) => e.value)
.sum;
static UsbPid fromValue(int value) {
return UsbPid.values.firstWhere((pid) => pid.value == value);
}
}
extension UsbInterfaces on UsbInterface {
int get value {
switch (this) {
case UsbInterface.otp:
return 0x01;
case UsbInterface.fido:
return 0x02;
case UsbInterface.ccid:
return 0x04;
}
}
static int forCapabilites(int capabilities) {
var interfaces = 0;
if (capabilities & Capability.otp.value != 0) {
interfaces |= UsbInterface.otp.value;
}
if (capabilities & (Capability.u2f.value | Capability.fido2.value) != 0) {
interfaces |= UsbInterface.fido.value;
}
if (capabilities &
(Capability.openpgp.value |
Capability.piv.value |
Capability.oath.value |
Capability.hsmauth.value) !=
0) {
interfaces |= UsbInterface.ccid.value;
}
return interfaces;
}
}
@freezed
class Version with _$Version {
@ -23,10 +134,3 @@ class Version with _$Version {
class Pair<T1, T2> with _$Pair<T1, T2> {
factory Pair(T1 first, T2 second) = _Pair<T1, T2>;
}
@freezed
class ApplicationStateResult<T> with _$ApplicationStateResult {
factory ApplicationStateResult.none() = _None;
factory ApplicationStateResult.failure(String reason) = _Failure;
factory ApplicationStateResult.success(T state) = _Success;
}

View File

@ -311,479 +311,3 @@ abstract class _Pair<T1, T2> implements Pair<T1, T2> {
_$PairCopyWith<T1, T2, _Pair<T1, T2>> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
class _$ApplicationStateResultTearOff {
const _$ApplicationStateResultTearOff();
_None<T> none<T>() {
return _None<T>();
}
_Failure<T> failure<T>(String reason) {
return _Failure<T>(
reason,
);
}
_Success<T> success<T>(T state) {
return _Success<T>(
state,
);
}
}
/// @nodoc
const $ApplicationStateResult = _$ApplicationStateResultTearOff();
/// @nodoc
mixin _$ApplicationStateResult<T> {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ApplicationStateResultCopyWith<T, $Res> {
factory $ApplicationStateResultCopyWith(ApplicationStateResult<T> value,
$Res Function(ApplicationStateResult<T>) then) =
_$ApplicationStateResultCopyWithImpl<T, $Res>;
}
/// @nodoc
class _$ApplicationStateResultCopyWithImpl<T, $Res>
implements $ApplicationStateResultCopyWith<T, $Res> {
_$ApplicationStateResultCopyWithImpl(this._value, this._then);
final ApplicationStateResult<T> _value;
// ignore: unused_field
final $Res Function(ApplicationStateResult<T>) _then;
}
/// @nodoc
abstract class _$NoneCopyWith<T, $Res> {
factory _$NoneCopyWith(_None<T> value, $Res Function(_None<T>) then) =
__$NoneCopyWithImpl<T, $Res>;
}
/// @nodoc
class __$NoneCopyWithImpl<T, $Res>
extends _$ApplicationStateResultCopyWithImpl<T, $Res>
implements _$NoneCopyWith<T, $Res> {
__$NoneCopyWithImpl(_None<T> _value, $Res Function(_None<T>) _then)
: super(_value, (v) => _then(v as _None<T>));
@override
_None<T> get _value => super._value as _None<T>;
}
/// @nodoc
class _$_None<T> implements _None<T> {
_$_None();
@override
String toString() {
return 'ApplicationStateResult<$T>.none()';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _None<T>);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) {
return none();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) {
return none?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) {
if (none != null) {
return none();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) {
return none(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) {
return none?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) {
if (none != null) {
return none(this);
}
return orElse();
}
}
abstract class _None<T> implements ApplicationStateResult<T> {
factory _None() = _$_None<T>;
}
/// @nodoc
abstract class _$FailureCopyWith<T, $Res> {
factory _$FailureCopyWith(
_Failure<T> value, $Res Function(_Failure<T>) then) =
__$FailureCopyWithImpl<T, $Res>;
$Res call({String reason});
}
/// @nodoc
class __$FailureCopyWithImpl<T, $Res>
extends _$ApplicationStateResultCopyWithImpl<T, $Res>
implements _$FailureCopyWith<T, $Res> {
__$FailureCopyWithImpl(_Failure<T> _value, $Res Function(_Failure<T>) _then)
: super(_value, (v) => _then(v as _Failure<T>));
@override
_Failure<T> get _value => super._value as _Failure<T>;
@override
$Res call({
Object? reason = freezed,
}) {
return _then(_Failure<T>(
reason == freezed
? _value.reason
: reason // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$_Failure<T> implements _Failure<T> {
_$_Failure(this.reason);
@override
final String reason;
@override
String toString() {
return 'ApplicationStateResult<$T>.failure(reason: $reason)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _Failure<T> &&
const DeepCollectionEquality().equals(other.reason, reason));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(reason));
@JsonKey(ignore: true)
@override
_$FailureCopyWith<T, _Failure<T>> get copyWith =>
__$FailureCopyWithImpl<T, _Failure<T>>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) {
return failure(reason);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) {
return failure?.call(reason);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) {
if (failure != null) {
return failure(reason);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) {
return failure(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) {
return failure?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) {
if (failure != null) {
return failure(this);
}
return orElse();
}
}
abstract class _Failure<T> implements ApplicationStateResult<T> {
factory _Failure(String reason) = _$_Failure<T>;
String get reason;
@JsonKey(ignore: true)
_$FailureCopyWith<T, _Failure<T>> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$SuccessCopyWith<T, $Res> {
factory _$SuccessCopyWith(
_Success<T> value, $Res Function(_Success<T>) then) =
__$SuccessCopyWithImpl<T, $Res>;
$Res call({T state});
}
/// @nodoc
class __$SuccessCopyWithImpl<T, $Res>
extends _$ApplicationStateResultCopyWithImpl<T, $Res>
implements _$SuccessCopyWith<T, $Res> {
__$SuccessCopyWithImpl(_Success<T> _value, $Res Function(_Success<T>) _then)
: super(_value, (v) => _then(v as _Success<T>));
@override
_Success<T> get _value => super._value as _Success<T>;
@override
$Res call({
Object? state = freezed,
}) {
return _then(_Success<T>(
state == freezed
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as T,
));
}
}
/// @nodoc
class _$_Success<T> implements _Success<T> {
_$_Success(this.state);
@override
final T state;
@override
String toString() {
return 'ApplicationStateResult<$T>.success(state: $state)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _Success<T> &&
const DeepCollectionEquality().equals(other.state, state));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(state));
@JsonKey(ignore: true)
@override
_$SuccessCopyWith<T, _Success<T>> get copyWith =>
__$SuccessCopyWithImpl<T, _Success<T>>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() none,
required TResult Function(String reason) failure,
required TResult Function(T state) success,
}) {
return success(state);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
}) {
return success?.call(state);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? none,
TResult Function(String reason)? failure,
TResult Function(T state)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(state);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_None<T> value) none,
required TResult Function(_Failure<T> value) failure,
required TResult Function(_Success<T> value) success,
}) {
return success(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
}) {
return success?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_None<T> value)? none,
TResult Function(_Failure<T> value)? failure,
TResult Function(_Success<T> value)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(this);
}
return orElse();
}
}
abstract class _Success<T> implements ApplicationStateResult<T> {
factory _Success(T state) = _$_Success<T>;
T get state;
@JsonKey(ignore: true)
_$SuccessCopyWith<T, _Success<T>> get copyWith =>
throw _privateConstructorUsedError;
}

27
lib/core/models.g.dart Executable file
View File

@ -0,0 +1,27 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'models.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
const _$UsbPidEnumMap = {
UsbPid.yksOtp: 16,
UsbPid.neoOtp: 272,
UsbPid.neoOtpCcid: 273,
UsbPid.neoCcid: 274,
UsbPid.neoFido: 275,
UsbPid.neoOtpFido: 276,
UsbPid.neoFidoCcid: 277,
UsbPid.neoOtpFidoCcid: 278,
UsbPid.skyFido: 288,
UsbPid.yk4Otp: 1025,
UsbPid.yk4Fido: 1026,
UsbPid.yk4OtpFido: 1027,
UsbPid.yk4Ccid: 1028,
UsbPid.yk4OtpCcid: 1029,
UsbPid.yk4FidoCcid: 1030,
UsbPid.yk4OtpFidoCcid: 1031,
UsbPid.ykpOtpFido: 1040,
};

View File

@ -5,7 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'models.dart';
import '../app/models.dart';
final isDesktop = Platform.isWindows || Platform.isMacOS || Platform.isLinux;
final isAndroid = Platform.isAndroid;

View File

@ -6,6 +6,7 @@ import 'package:logging/logging.dart';
import '../app/models.dart';
import '../app/state.dart';
import '../core/models.dart';
import '../management/models.dart';
import 'models.dart';
import 'rpc.dart';
@ -63,7 +64,7 @@ class UsbDeviceNotifier extends StateNotifier<List<UsbYubiKeyNode>> {
var scan = await _rpc.command('scan', ['usb']);
final pids = {
for (var e in (scan['pids'] as Map).entries)
int.parse(e.key): e.value as int
UsbPids.fromValue(int.parse(e.key)): e.value as int
};
final numDevices = pids.values.fold<int>(0, (a, b) => a + b);
if (_usbState != scan['state'] || state.length != numDevices) {
@ -76,7 +77,7 @@ class UsbDeviceNotifier extends StateNotifier<List<UsbYubiKeyNode>> {
final path = ['usb', id];
final deviceResult = await _rpc.command('get', path);
final deviceData = deviceResult['data'];
final pid = deviceData['pid'] as int;
final pid = UsbPids.fromValue(deviceData['pid'] as int);
usbDevices.add(DeviceNode.usbYubiKey(
DevicePath(path),
deviceData['name'],
@ -92,7 +93,7 @@ class UsbDeviceNotifier extends StateNotifier<List<UsbYubiKeyNode>> {
for (var i = 0; i < count; i++) {
usbDevices.add(DeviceNode.usbYubiKey(
DevicePath(['invalid', '$pid-$i']),
'YubiKey ($pid)',
pid.displayName,
pid,
null) as UsbYubiKeyNode);
}

View File

@ -5,8 +5,6 @@ import '../core/models.dart';
part 'models.freezed.dart';
part 'models.g.dart';
enum Transport { usb, nfc }
enum FormFactor {
@JsonValue(0)
unknown,
@ -26,40 +24,6 @@ enum FormFactor {
usbCBio,
}
enum UsbInterface { otp, fido, ccid }
extension UsbInterfaces on UsbInterface {
int get value {
switch (this) {
case UsbInterface.otp:
return 0x01;
case UsbInterface.fido:
return 0x02;
case UsbInterface.ccid:
return 0x04;
}
}
static int forCapabilites(int capabilities) {
var interfaces = 0;
if (capabilities & Capability.otp.value != 0) {
interfaces |= UsbInterface.otp.value;
}
if (capabilities & (Capability.u2f.value | Capability.fido2.value) != 0) {
interfaces |= UsbInterface.fido.value;
}
if (capabilities &
(Capability.openpgp.value |
Capability.piv.value |
Capability.oath.value |
Capability.hsmauth.value) !=
0) {
interfaces |= UsbInterface.ccid.value;
}
return interfaces;
}
}
enum Capability { otp, piv, oath, openpgp, hsmauth, u2f, fido2 }
extension CapabilityExtension on Capability {

View File

@ -7,6 +7,7 @@ import '../../app/state.dart';
import '../../app/views/app_failure_screen.dart';
import '../../app/views/app_loading_screen.dart';
import '../../app/views/responsive_dialog.dart';
import '../../core/models.dart';
import '../models.dart';
import '../state.dart';