yubioath-flutter/lib/fido/models.dart

101 lines
2.9 KiB
Dart
Raw Normal View History

2022-10-04 13:12:54 +03:00
/*
* Copyright (C) 2022 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2022-03-15 19:16:14 +03:00
import 'package:freezed_annotation/freezed_annotation.dart';
part 'models.freezed.dart';
part 'models.g.dart';
2022-03-17 22:10:10 +03:00
enum InteractionEvent { remove, insert, touch }
2022-03-15 19:16:14 +03:00
@freezed
class FidoState with _$FidoState {
const FidoState._();
factory FidoState(
{required Map<String, dynamic> info,
required bool unlocked,
int? pinRetries}) = _FidoState;
2022-03-15 19:16:14 +03:00
factory FidoState.fromJson(Map<String, dynamic> json) =>
_$FidoStateFromJson(json);
bool get hasPin => info['options']['clientPin'] == true;
2022-03-17 15:06:48 +03:00
int get minPinLength => info['min_pin_length'] as int;
bool get credMgmt =>
info['options']['credMgmt'] == true ||
info['options']['credentialMgmtPreview'] == true;
2024-03-20 19:46:08 +03:00
int? get remainingCreds => info['remaining_disc_creds'];
2022-03-17 15:06:48 +03:00
bool? get bioEnroll => info['options']['bioEnroll'];
bool get alwaysUv => info['options']['alwaysUv'] == true;
2023-09-27 16:12:31 +03:00
bool get forcePinChange => info['force_pin_change'] == true;
bool get pinBlocked => pinRetries == 0;
2024-07-03 17:15:12 +03:00
bool? get enterpriseAttestation => info['options']['ep'];
2022-03-17 15:06:48 +03:00
}
@freezed
class PinResult with _$PinResult {
factory PinResult.success() = _PinSuccess;
2024-03-26 16:07:23 +03:00
factory PinResult.failed(FidoPinFailureReason reason) = _PinFailure;
}
@freezed
class FidoPinFailureReason with _$FidoPinFailureReason {
factory FidoPinFailureReason.invalidPin(int retries, bool authBlocked) =
FidoInvalidPin;
const factory FidoPinFailureReason.weakPin() = FidoWeakPin;
}
@freezed
class Fingerprint with _$Fingerprint {
2022-03-23 11:49:20 +03:00
const Fingerprint._();
factory Fingerprint(String templateId, String? name) = _Fingerprint;
factory Fingerprint.fromJson(Map<String, dynamic> json) =>
_$FingerprintFromJson(json);
String get label => name ?? 'Unnamed (ID: $templateId)';
}
@freezed
class FingerprintEvent with _$FingerprintEvent {
factory FingerprintEvent.capture(int remaining) = _EventCapture;
2022-03-23 11:49:20 +03:00
factory FingerprintEvent.complete(Fingerprint fingerprint) = _EventComplete;
factory FingerprintEvent.error(int code) = _EventError;
}
@freezed
class FidoCredential with _$FidoCredential {
2022-03-23 19:50:49 +03:00
factory FidoCredential({
required String rpId,
required String credentialId,
required String userId,
required String userName,
2024-03-28 14:55:28 +03:00
String? displayName,
2022-03-23 19:50:49 +03:00
}) = _FidoCredential;
factory FidoCredential.fromJson(Map<String, dynamic> json) =>
_$FidoCredentialFromJson(json);
2022-03-15 19:16:14 +03:00
}