yubioath-flutter/lib/fido/models.dart

87 lines
2.5 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,
2024-02-01 18:53:17 +03:00
required bool unlocked,
@Default(true) bool initialized}) = _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;
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;
2022-03-17 15:06:48 +03:00
}
@freezed
class PinResult with _$PinResult {
factory PinResult.success() = _PinSuccess;
factory PinResult.failed(int retries, bool authBlocked) = _PinFailure;
}
@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,
}) = _FidoCredential;
factory FidoCredential.fromJson(Map<String, dynamic> json) =>
_$FidoCredentialFromJson(json);
2022-03-15 19:16:14 +03:00
}