Skip to content

Commit

Permalink
rename TYPE constant to OTPAUTH_TYPE and update related references
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Dec 18, 2024
1 parent 0e62a6b commit 8bca5b7
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 125 deletions.
4 changes: 2 additions & 2 deletions lib/model/token_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class TokenTemplate with _$TokenTemplate {
);

String? get type => validateOptional(
value: otpAuthMap[Token.TYPE],
value: otpAuthMap[Token.OTPAUTH_TYPE],
validator: const ObjectValidatorNullable<String>(),
name: Token.TYPE,
name: Token.OTPAUTH_TYPE,
);

List<String>? get otpValues => this is _TokenTemplateWithOtps ? (this as _TokenTemplateWithOtps).otps : null;
Expand Down
7 changes: 4 additions & 3 deletions lib/model/tokens/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ abstract class Token with SortableMixin {
static const String IMAGE = 'image';

// Default data keys
static const String TYPE = 'tokentype';
static const String OTPAUTH_TYPE = 'tokentype';
static const String TYPE = 'type';

/// [String] (optional) default = ''
static const String LABEL = 'label';
Expand Down Expand Up @@ -110,7 +111,7 @@ abstract class Token with SortableMixin {

/// Creates a token from a uri map.
factory Token.fromOtpAuthMap(Map<String, dynamic> otpAuthMap, {Map<String, dynamic> additionalData = const {}}) {
String? type = otpAuthMap[TYPE];
String? type = otpAuthMap[OTPAUTH_TYPE];
if (type == null) throw ArgumentError.value(otpAuthMap, 'Token#fromUriMap', 'Token type is not defined in the uri map');
if (TokenTypes.HOTP.isName(type, caseSensitive: false)) return HOTPToken.fromOtpAuthMap(otpAuthMap, additionalData: additionalData);
if (TokenTypes.TOTP.isName(type, caseSensitive: false)) return TOTPToken.fromOtpAuthMap(otpAuthMap, additionalData: additionalData);
Expand Down Expand Up @@ -224,7 +225,7 @@ abstract class Token with SortableMixin {
Map<String, dynamic> toOtpAuthMap() {
return {
if (serial != null) SERIAL: serial!,
TYPE: type,
OTPAUTH_TYPE: type,
LABEL: label,
ISSUER: issuer,
PIN: pin ? PIN_VALUE_TRUE : PIN_VALUE_FALSE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class OtpAuthProcessor extends TokenImportSchemeProcessor {
final (label, issuer) = _parseLabelAndIssuer(uri);
queryParameters[Token.LABEL] = label;
queryParameters[Token.ISSUER] = issuer;
queryParameters[Token.TYPE] = _parseTokenType(uri);
queryParameters[Token.OTPAUTH_TYPE] = _parseTokenType(uri);
queryParameters = _secretAddPadding(queryParameters);

_logInfo(uri);
Expand Down Expand Up @@ -216,12 +216,12 @@ Map<String, String> _secretAddPadding(Map<String, String> queryParameters) {
String _parseTokenType(Uri uri) {
if (_parseIssuer(uri) == "Steam") return TokenTypes.STEAM.name;
Logger.debug('Token type host: ${uri.host}');
Logger.debug('Token type queryParameters: ${uri.queryParameters[Token.TYPE]}');
final value = uri.queryParameters[Token.TYPE] ?? uri.host;
Logger.debug('Token type queryParameters: ${uri.queryParameters[Token.OTPAUTH_TYPE]}');
final value = uri.queryParameters[Token.OTPAUTH_TYPE] ?? uri.host;
Logger.debug('Token type value: $value');
return validate(
value: uri.queryParameters[Token.TYPE] ?? uri.host,
value: uri.queryParameters[Token.OTPAUTH_TYPE] ?? uri.host,
validator: ObjectValidator<String>(defaultValue: uri.host),
name: Token.TYPE,
name: Token.OTPAUTH_TYPE,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class AegisImportFileProcessor extends TokenImportFileProcessor {
Map<String, dynamic> info = entry[AEGIS_ENTRY_INFO];
final otpAuthMap = validateMap<String>(
map: {
Token.TYPE: entry[AEGIS_ENTRY_TYPE],
Token.OTPAUTH_TYPE: entry[AEGIS_ENTRY_TYPE],
Token.LABEL: entry[AEGIS_ENTRY_LABEL],
Token.ISSUER: entry[AEGIS_ENTRY_ISSUER],
Token.PIN: info[AEGIS_INFO_PIN],
Expand All @@ -199,7 +199,7 @@ class AegisImportFileProcessor extends TokenImportFileProcessor {
HOTPToken.COUNTER: info[AEGIS_INFO_COUNTER],
},
validators: {
Token.TYPE: const ObjectValidator<String>(),
Token.OTPAUTH_TYPE: const ObjectValidator<String>(),
Token.LABEL: const ObjectValidator<String>(defaultValue: ''),
Token.ISSUER: const ObjectValidator<String>(defaultValue: ''),
Token.PIN: const ObjectValidatorNullable<String>(),
Expand Down Expand Up @@ -247,7 +247,7 @@ class AegisImportFileProcessor extends TokenImportFileProcessor {
Map<String, dynamic> info = entry[AEGIS_ENTRY_INFO];
final otpAuthMap = validateMap<String>(
map: {
Token.TYPE: entry[AEGIS_ENTRY_TYPE],
Token.OTPAUTH_TYPE: entry[AEGIS_ENTRY_TYPE],
Token.LABEL: entry[AEGIS_ENTRY_LABEL],
Token.ISSUER: entry[AEGIS_ENTRY_ISSUER],
OTPToken.SECRET_BASE32: info[AEGIS_INFO_SECRET],
Expand All @@ -258,7 +258,7 @@ class AegisImportFileProcessor extends TokenImportFileProcessor {
Token.PIN: info[AEGIS_INFO_PIN],
},
validators: {
Token.TYPE: const ObjectValidator<String>(),
Token.OTPAUTH_TYPE: const ObjectValidator<String>(),
Token.LABEL: const ObjectValidator<String>(defaultValue: ''),
Token.ISSUER: const ObjectValidator<String>(defaultValue: ''),
OTPToken.SECRET_BASE32: ObjectValidator<String>(transformer: (v) => Encodings.base32.encodeStringTo(Encodings.base32, v)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class AuthenticatorProImportFileProcessor extends TokenImportFileProcessor {

final otpAuthMap = validateMap<String>(
map: {
Token.TYPE: tokenType,
Token.OTPAUTH_TYPE: tokenType,
Token.ISSUER: tokenMap[_AUTHENTICATOR_PRO_ISSUER],
Token.LABEL: tokenMap[_AUTHENTICATOR_PRO_LABEL],
OTPToken.SECRET_BASE32: tokenMap[_AUTHENTICATOR_PRO_SECRET],
Expand All @@ -331,7 +331,7 @@ class AuthenticatorProImportFileProcessor extends TokenImportFileProcessor {
HOTPToken.COUNTER: tokenMap[_AUTHENTICATOR_PRO_COUNTER],
},
validators: {
Token.TYPE: const ObjectValidator<String>(),
Token.OTPAUTH_TYPE: const ObjectValidator<String>(),
Token.ISSUER: const ObjectValidator<String>(),
Token.LABEL: const ObjectValidator<String>(),
OTPToken.SECRET_BASE32: const ObjectValidator<String>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class FreeOtpPlusImportFileProcessor extends TokenImportFileProcessor {
name: 'FreeOtpPlusToken',
map: {
/// Steam is a special case, its hardcoded in the original app.
Token.TYPE: tokenJson[_FREE_OTP_PLUS_ISSUER] == _steamTokenIssuer ? _steamTokenType : tokenJson[_FREE_OTP_PLUS_TYPE],
Token.OTPAUTH_TYPE: tokenJson[_FREE_OTP_PLUS_ISSUER] == _steamTokenIssuer ? _steamTokenType : tokenJson[_FREE_OTP_PLUS_TYPE],
Token.LABEL: tokenJson[_FREE_OTP_PLUS_LABEL],
Token.ISSUER: tokenJson[_FREE_OTP_PLUS_ISSUER],
OTPToken.SECRET_BASE32: tokenJson[_FREE_OTP_PLUS_SECRET],
Expand All @@ -166,7 +166,7 @@ class FreeOtpPlusImportFileProcessor extends TokenImportFileProcessor {
TOTPToken.PERIOD_SECONDS: tokenJson[_FREE_OTP_PLUS_PERIOD],
},
validators: {
Token.TYPE: const ObjectValidator<String>(),
Token.OTPAUTH_TYPE: const ObjectValidator<String>(),
Token.LABEL: const ObjectValidator<String>(),
Token.ISSUER: const ObjectValidator<String>(),
OTPToken.SECRET_BASE32: ObjectValidator<String>(transformer: (value) => Encodings.base32.encode(Uint8List.fromList((value as List).cast<int>()))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class TwoFasAuthenticatorImportFileProcessor extends TokenImportFileProcessor {
return validateMap(
map: {
Token.ISSUER: twoFasToken[TWOFAS_ISSUER],
Token.TYPE: twoFasOTP[TWOFAS_TYPE],
Token.OTPAUTH_TYPE: twoFasOTP[TWOFAS_TYPE],
Token.LABEL: twoFasOTP[TWOFAS_LABEL],
OTPToken.SECRET_BASE32: twoFasToken[TWOFAS_SECRET],
OTPToken.ALGORITHM: twoFasOTP[TWOFAS_ALGORITHM],
Expand All @@ -184,7 +184,7 @@ class TwoFasAuthenticatorImportFileProcessor extends TokenImportFileProcessor {
HOTPToken.COUNTER: twoFasOTP[TWOFAS_COUNTER],
},
validators: {
Token.TYPE: const ObjectValidator<String>(),
Token.OTPAUTH_TYPE: const ObjectValidator<String>(),
Token.ISSUER: const ObjectValidatorNullable<String>(),
Token.LABEL: const ObjectValidatorNullable<String>(),
OTPToken.SECRET_BASE32: const ObjectValidator<String>(),
Expand Down
Loading

0 comments on commit 8bca5b7

Please sign in to comment.