chore: use .value for scrobble encrypted text

This commit is contained in:
Kingkor Roy Tirtho 2024-06-20 23:30:41 +06:00
parent 5936f08a92
commit 59041a2948
2 changed files with 40 additions and 33 deletions

View File

@ -1763,9 +1763,12 @@ class $ScrobblerTableTable extends ScrobblerTable
static const VerificationMeta _passwordHashMeta = static const VerificationMeta _passwordHashMeta =
const VerificationMeta('passwordHash'); const VerificationMeta('passwordHash');
@override @override
late final GeneratedColumn<String> passwordHash = GeneratedColumn<String>( late final GeneratedColumnWithTypeConverter<DecryptedText, String>
passwordHash = GeneratedColumn<String>(
'password_hash', aliasedName, false, 'password_hash', aliasedName, false,
type: DriftSqlType.string, requiredDuringInsert: true); type: DriftSqlType.string, requiredDuringInsert: true)
.withConverter<DecryptedText>(
$ScrobblerTableTable.$converterpasswordHash);
@override @override
List<GeneratedColumn> get $columns => [id, createdAt, username, passwordHash]; List<GeneratedColumn> get $columns => [id, createdAt, username, passwordHash];
@override @override
@ -1791,14 +1794,7 @@ class $ScrobblerTableTable extends ScrobblerTable
} else if (isInserting) { } else if (isInserting) {
context.missing(_usernameMeta); context.missing(_usernameMeta);
} }
if (data.containsKey('password_hash')) { context.handle(_passwordHashMeta, const VerificationResult.success());
context.handle(
_passwordHashMeta,
passwordHash.isAcceptableOrUnknown(
data['password_hash']!, _passwordHashMeta));
} else if (isInserting) {
context.missing(_passwordHashMeta);
}
return context; return context;
} }
@ -1814,8 +1810,9 @@ class $ScrobblerTableTable extends ScrobblerTable
.read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!, .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!,
username: attachedDatabase.typeMapping username: attachedDatabase.typeMapping
.read(DriftSqlType.string, data['${effectivePrefix}username'])!, .read(DriftSqlType.string, data['${effectivePrefix}username'])!,
passwordHash: attachedDatabase.typeMapping passwordHash: $ScrobblerTableTable.$converterpasswordHash.fromSql(
.read(DriftSqlType.string, data['${effectivePrefix}password_hash'])!, attachedDatabase.typeMapping.read(
DriftSqlType.string, data['${effectivePrefix}password_hash'])!),
); );
} }
@ -1823,6 +1820,9 @@ class $ScrobblerTableTable extends ScrobblerTable
$ScrobblerTableTable createAlias(String alias) { $ScrobblerTableTable createAlias(String alias) {
return $ScrobblerTableTable(attachedDatabase, alias); return $ScrobblerTableTable(attachedDatabase, alias);
} }
static TypeConverter<DecryptedText, String> $converterpasswordHash =
EncryptedTextConverter();
} }
class ScrobblerTableData extends DataClass class ScrobblerTableData extends DataClass
@ -1830,7 +1830,7 @@ class ScrobblerTableData extends DataClass
final int id; final int id;
final DateTime createdAt; final DateTime createdAt;
final String username; final String username;
final String passwordHash; final DecryptedText passwordHash;
const ScrobblerTableData( const ScrobblerTableData(
{required this.id, {required this.id,
required this.createdAt, required this.createdAt,
@ -1842,7 +1842,10 @@ class ScrobblerTableData extends DataClass
map['id'] = Variable<int>(id); map['id'] = Variable<int>(id);
map['created_at'] = Variable<DateTime>(createdAt); map['created_at'] = Variable<DateTime>(createdAt);
map['username'] = Variable<String>(username); map['username'] = Variable<String>(username);
map['password_hash'] = Variable<String>(passwordHash); {
map['password_hash'] = Variable<String>(
$ScrobblerTableTable.$converterpasswordHash.toSql(passwordHash));
}
return map; return map;
} }
@ -1862,7 +1865,7 @@ class ScrobblerTableData extends DataClass
id: serializer.fromJson<int>(json['id']), id: serializer.fromJson<int>(json['id']),
createdAt: serializer.fromJson<DateTime>(json['createdAt']), createdAt: serializer.fromJson<DateTime>(json['createdAt']),
username: serializer.fromJson<String>(json['username']), username: serializer.fromJson<String>(json['username']),
passwordHash: serializer.fromJson<String>(json['passwordHash']), passwordHash: serializer.fromJson<DecryptedText>(json['passwordHash']),
); );
} }
@override @override
@ -1872,7 +1875,7 @@ class ScrobblerTableData extends DataClass
'id': serializer.toJson<int>(id), 'id': serializer.toJson<int>(id),
'createdAt': serializer.toJson<DateTime>(createdAt), 'createdAt': serializer.toJson<DateTime>(createdAt),
'username': serializer.toJson<String>(username), 'username': serializer.toJson<String>(username),
'passwordHash': serializer.toJson<String>(passwordHash), 'passwordHash': serializer.toJson<DecryptedText>(passwordHash),
}; };
} }
@ -1880,7 +1883,7 @@ class ScrobblerTableData extends DataClass
{int? id, {int? id,
DateTime? createdAt, DateTime? createdAt,
String? username, String? username,
String? passwordHash}) => DecryptedText? passwordHash}) =>
ScrobblerTableData( ScrobblerTableData(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
@ -1914,7 +1917,7 @@ class ScrobblerTableCompanion extends UpdateCompanion<ScrobblerTableData> {
final Value<int> id; final Value<int> id;
final Value<DateTime> createdAt; final Value<DateTime> createdAt;
final Value<String> username; final Value<String> username;
final Value<String> passwordHash; final Value<DecryptedText> passwordHash;
const ScrobblerTableCompanion({ const ScrobblerTableCompanion({
this.id = const Value.absent(), this.id = const Value.absent(),
this.createdAt = const Value.absent(), this.createdAt = const Value.absent(),
@ -1925,7 +1928,7 @@ class ScrobblerTableCompanion extends UpdateCompanion<ScrobblerTableData> {
this.id = const Value.absent(), this.id = const Value.absent(),
this.createdAt = const Value.absent(), this.createdAt = const Value.absent(),
required String username, required String username,
required String passwordHash, required DecryptedText passwordHash,
}) : username = Value(username), }) : username = Value(username),
passwordHash = Value(passwordHash); passwordHash = Value(passwordHash);
static Insertable<ScrobblerTableData> custom({ static Insertable<ScrobblerTableData> custom({
@ -1946,7 +1949,7 @@ class ScrobblerTableCompanion extends UpdateCompanion<ScrobblerTableData> {
{Value<int>? id, {Value<int>? id,
Value<DateTime>? createdAt, Value<DateTime>? createdAt,
Value<String>? username, Value<String>? username,
Value<String>? passwordHash}) { Value<DecryptedText>? passwordHash}) {
return ScrobblerTableCompanion( return ScrobblerTableCompanion(
id: id ?? this.id, id: id ?? this.id,
createdAt: createdAt ?? this.createdAt, createdAt: createdAt ?? this.createdAt,
@ -1968,7 +1971,9 @@ class ScrobblerTableCompanion extends UpdateCompanion<ScrobblerTableData> {
map['username'] = Variable<String>(username.value); map['username'] = Variable<String>(username.value);
} }
if (passwordHash.present) { if (passwordHash.present) {
map['password_hash'] = Variable<String>(passwordHash.value); map['password_hash'] = Variable<String>($ScrobblerTableTable
.$converterpasswordHash
.toSql(passwordHash.value));
} }
return map; return map;
} }
@ -3342,14 +3347,14 @@ typedef $$ScrobblerTableTableInsertCompanionBuilder = ScrobblerTableCompanion
Value<int> id, Value<int> id,
Value<DateTime> createdAt, Value<DateTime> createdAt,
required String username, required String username,
required String passwordHash, required DecryptedText passwordHash,
}); });
typedef $$ScrobblerTableTableUpdateCompanionBuilder = ScrobblerTableCompanion typedef $$ScrobblerTableTableUpdateCompanionBuilder = ScrobblerTableCompanion
Function({ Function({
Value<int> id, Value<int> id,
Value<DateTime> createdAt, Value<DateTime> createdAt,
Value<String> username, Value<String> username,
Value<String> passwordHash, Value<DecryptedText> passwordHash,
}); });
class $$ScrobblerTableTableTableManager extends RootTableManager< class $$ScrobblerTableTableTableManager extends RootTableManager<
@ -3376,7 +3381,7 @@ class $$ScrobblerTableTableTableManager extends RootTableManager<
Value<int> id = const Value.absent(), Value<int> id = const Value.absent(),
Value<DateTime> createdAt = const Value.absent(), Value<DateTime> createdAt = const Value.absent(),
Value<String> username = const Value.absent(), Value<String> username = const Value.absent(),
Value<String> passwordHash = const Value.absent(), Value<DecryptedText> passwordHash = const Value.absent(),
}) => }) =>
ScrobblerTableCompanion( ScrobblerTableCompanion(
id: id, id: id,
@ -3388,7 +3393,7 @@ class $$ScrobblerTableTableTableManager extends RootTableManager<
Value<int> id = const Value.absent(), Value<int> id = const Value.absent(),
Value<DateTime> createdAt = const Value.absent(), Value<DateTime> createdAt = const Value.absent(),
required String username, required String username,
required String passwordHash, required DecryptedText passwordHash,
}) => }) =>
ScrobblerTableCompanion.insert( ScrobblerTableCompanion.insert(
id: id, id: id,
@ -3429,10 +3434,12 @@ class $$ScrobblerTableTableFilterComposer
builder: (column, joinBuilders) => builder: (column, joinBuilders) =>
ColumnFilters(column, joinBuilders: joinBuilders)); ColumnFilters(column, joinBuilders: joinBuilders));
ColumnFilters<String> get passwordHash => $state.composableBuilder( ColumnWithTypeConverterFilters<DecryptedText, DecryptedText, String>
get passwordHash => $state.composableBuilder(
column: $state.table.passwordHash, column: $state.table.passwordHash,
builder: (column, joinBuilders) => builder: (column, joinBuilders) => ColumnWithTypeConverterFilters(
ColumnFilters(column, joinBuilders: joinBuilders)); column,
joinBuilders: joinBuilders));
} }
class $$ScrobblerTableTableOrderingComposer class $$ScrobblerTableTableOrderingComposer

View File

@ -30,7 +30,7 @@ class ScrobblerNotifier extends AsyncNotifier<Scrobblenaut?> {
apiKey: Env.lastFmApiKey, apiKey: Env.lastFmApiKey,
apiSecret: Env.lastFmApiSecret, apiSecret: Env.lastFmApiSecret,
username: event.first.username, username: event.first.username,
passwordHash: event.first.passwordHash, passwordHash: event.first.passwordHash.value,
), ),
), ),
); );
@ -70,7 +70,7 @@ class ScrobblerNotifier extends AsyncNotifier<Scrobblenaut?> {
apiKey: Env.lastFmApiKey, apiKey: Env.lastFmApiKey,
apiSecret: Env.lastFmApiSecret, apiSecret: Env.lastFmApiSecret,
username: loginInfo.username, username: loginInfo.username,
passwordHash: loginInfo.passwordHash, passwordHash: loginInfo.passwordHash.value,
), ),
); );
} }
@ -94,7 +94,7 @@ class ScrobblerNotifier extends AsyncNotifier<Scrobblenaut?> {
ScrobblerTableCompanion.insert( ScrobblerTableCompanion.insert(
id: const Value(0), id: const Value(0),
username: username, username: username,
passwordHash: lastFm.passwordHash!, passwordHash: DecryptedText(lastFm.passwordHash!),
), ),
); );
} }