Use JsonConverter for Issuer field

This commit is contained in:
Adam Velebil 2024-01-24 09:36:33 +01:00
parent ab6d44d31c
commit 6597bf5bb5
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
8 changed files with 56 additions and 49 deletions

View File

@ -153,7 +153,7 @@ class _$YubiKeyDataImpl implements _YubiKeyData {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$YubiKeyDataImpl &&
@ -363,7 +363,7 @@ class _$UsbYubiKeyNodeImpl extends UsbYubiKeyNode {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UsbYubiKeyNodeImpl &&
@ -523,7 +523,7 @@ class _$NfcReaderNodeImpl extends NfcReaderNode {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$NfcReaderNodeImpl &&
@ -844,7 +844,7 @@ class _$ActionItemImpl implements _ActionItem {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ActionItemImpl &&
@ -1043,7 +1043,7 @@ class _$WindowStateImpl implements _WindowState {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$WindowStateImpl &&

View File

@ -128,7 +128,7 @@ class _$VersionImpl extends _Version {
final int patch;
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$VersionImpl &&

View File

@ -168,7 +168,7 @@ class _$DeviceConfigImpl implements _DeviceConfig {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$DeviceConfigImpl &&
@ -475,7 +475,7 @@ class _$DeviceInfoImpl implements _DeviceInfo {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$DeviceInfoImpl &&

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Yubico.
* Copyright (C) 2022-2024 Yubico.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -65,20 +65,24 @@ class OathCredential with _$OathCredential {
factory OathCredential(
String deviceId,
String id,
String? issuer,
@_IssuerConverter() String? issuer,
String name,
OathType oathType,
int period,
bool touchRequired) = _OathCredential;
factory OathCredential.fromJson(Map<String, dynamic> json) {
final value = _$OathCredentialFromJson(json);
// Replace empty issuer string with null
return switch (value.issuer) {
(String issuer) when issuer.isEmpty => value.copyWith(issuer: null),
_ => value,
};
}
factory OathCredential.fromJson(Map<String, dynamic> json) =>
_$OathCredentialFromJson(json);
}
class _IssuerConverter implements JsonConverter<String?, String?> {
const _IssuerConverter();
@override
String? fromJson(String? json) => json != null && json.isEmpty ? null : json;
@override
String? toJson(String? object) => object;
}
@freezed

View File

@ -22,6 +22,7 @@ OathCredential _$OathCredentialFromJson(Map<String, dynamic> json) {
mixin _$OathCredential {
String get deviceId => throw _privateConstructorUsedError;
String get id => throw _privateConstructorUsedError;
@_IssuerConverter()
String? get issuer => throw _privateConstructorUsedError;
String get name => throw _privateConstructorUsedError;
OathType get oathType => throw _privateConstructorUsedError;
@ -43,7 +44,7 @@ abstract class $OathCredentialCopyWith<$Res> {
$Res call(
{String deviceId,
String id,
String? issuer,
@_IssuerConverter() String? issuer,
String name,
OathType oathType,
int period,
@ -115,7 +116,7 @@ abstract class _$$OathCredentialImplCopyWith<$Res>
$Res call(
{String deviceId,
String id,
String? issuer,
@_IssuerConverter() String? issuer,
String name,
OathType oathType,
int period,
@ -177,8 +178,8 @@ class __$$OathCredentialImplCopyWithImpl<$Res>
/// @nodoc
@JsonSerializable()
class _$OathCredentialImpl implements _OathCredential {
_$OathCredentialImpl(this.deviceId, this.id, this.issuer, this.name,
this.oathType, this.period, this.touchRequired);
_$OathCredentialImpl(this.deviceId, this.id, @_IssuerConverter() this.issuer,
this.name, this.oathType, this.period, this.touchRequired);
factory _$OathCredentialImpl.fromJson(Map<String, dynamic> json) =>
_$$OathCredentialImplFromJson(json);
@ -188,6 +189,7 @@ class _$OathCredentialImpl implements _OathCredential {
@override
final String id;
@override
@_IssuerConverter()
final String? issuer;
@override
final String name;
@ -204,7 +206,7 @@ class _$OathCredentialImpl implements _OathCredential {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OathCredentialImpl &&
@ -244,7 +246,7 @@ abstract class _OathCredential implements OathCredential {
factory _OathCredential(
final String deviceId,
final String id,
final String? issuer,
@_IssuerConverter() final String? issuer,
final String name,
final OathType oathType,
final int period,
@ -258,6 +260,7 @@ abstract class _OathCredential implements OathCredential {
@override
String get id;
@override
@_IssuerConverter()
String? get issuer;
@override
String get name;
@ -395,7 +398,7 @@ class _$OathCodeImpl implements _OathCode {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OathCodeImpl &&
@ -580,7 +583,7 @@ class _$OathPairImpl implements _OathPair {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OathPairImpl &&
@ -814,7 +817,7 @@ class _$OathStateImpl implements _OathState {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$OathStateImpl &&
@ -1094,7 +1097,7 @@ class _$CredentialDataImpl extends _CredentialData {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CredentialDataImpl &&

View File

@ -10,7 +10,7 @@ _$OathCredentialImpl _$$OathCredentialImplFromJson(Map<String, dynamic> json) =>
_$OathCredentialImpl(
json['device_id'] as String,
json['id'] as String,
json['issuer'] as String?,
const _IssuerConverter().fromJson(json['issuer'] as String?),
json['name'] as String,
$enumDecode(_$OathTypeEnumMap, json['oath_type']),
json['period'] as int,
@ -22,7 +22,7 @@ Map<String, dynamic> _$$OathCredentialImplToJson(
<String, dynamic>{
'device_id': instance.deviceId,
'id': instance.id,
'issuer': instance.issuer,
'issuer': const _IssuerConverter().toJson(instance.issuer),
'name': instance.name,
'oath_type': _$OathTypeEnumMap[instance.oathType]!,
'period': instance.period,

View File

@ -138,7 +138,7 @@ class _$PinMetadataImpl implements _PinMetadata {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PinMetadataImpl &&
@ -276,7 +276,7 @@ class _$PinSuccessImpl implements _PinSuccess {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$PinSuccessImpl);
}
@ -396,7 +396,7 @@ class _$PinFailureImpl implements _PinFailure {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PinFailureImpl &&
@ -615,7 +615,7 @@ class _$ManagementKeyMetadataImpl implements _ManagementKeyMetadata {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ManagementKeyMetadataImpl &&
@ -827,7 +827,7 @@ class _$SlotMetadataImpl implements _SlotMetadata {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SlotMetadataImpl &&
@ -1057,7 +1057,7 @@ class _$PivStateMetadataImpl implements _PivStateMetadata {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PivStateMetadataImpl &&
@ -1350,7 +1350,7 @@ class _$PivStateImpl extends _PivState {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PivStateImpl &&
@ -1604,7 +1604,7 @@ class _$CertInfoImpl implements _CertInfo {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CertInfoImpl &&
@ -1805,7 +1805,7 @@ class _$PivSlotImpl implements _PivSlot {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PivSlotImpl &&
@ -2015,7 +2015,7 @@ class _$ExamineResultImpl implements _ExamineResult {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ExamineResultImpl &&
@ -2161,7 +2161,7 @@ class _$InvalidPasswordImpl implements _InvalidPassword {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$InvalidPasswordImpl);
}
@ -2398,7 +2398,7 @@ class _$GenerateCertificateImpl implements _GenerateCertificate {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$GenerateCertificateImpl &&
@ -2548,7 +2548,7 @@ class _$GenerateCsrImpl implements _GenerateCsr {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$GenerateCsrImpl &&
@ -2768,7 +2768,7 @@ class _$PivGenerateResultImpl implements _PivGenerateResult {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PivGenerateResultImpl &&
@ -2962,7 +2962,7 @@ class _$PivImportResultImpl implements _PivImportResult {
}
@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$PivImportResultImpl &&

View File

@ -48,7 +48,7 @@ dependencies:
shared_preferences: ^2.2.2
flutter_riverpod: ^2.4.9
json_annotation: ^4.8.1
freezed_annotation: ^2.2.0
freezed_annotation: ^2.4.1
window_manager: ^0.3.7
qrscanner_zxing:
path: android/flutter_plugins/qrscanner_zxing
@ -83,9 +83,9 @@ dev_dependencies:
# rules and activating additional ones.
flutter_lints: ^3.0.1
build_runner: ^2.4.7
freezed: ^2.4.5
json_serializable: ^6.7.0
build_runner: ^2.4.8
freezed: ^2.4.6
json_serializable: ^6.7.1
analyzer:
analyzer_plugin:
custom_lint_builder: