2021-02-03 20:26:38 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:hive/hive.dart';
|
|
|
|
|
|
|
|
part 'backblaze_credential.g.dart';
|
|
|
|
|
|
|
|
@HiveType(typeId: 4)
|
|
|
|
class BackblazeCredential {
|
2021-03-26 13:38:39 +00:00
|
|
|
BackblazeCredential({required this.keyId, required this.applicationKey});
|
2021-02-03 20:26:38 +00:00
|
|
|
|
|
|
|
@HiveField(0)
|
2021-03-26 13:38:39 +00:00
|
|
|
final String keyId;
|
2021-02-03 20:26:38 +00:00
|
|
|
|
|
|
|
@HiveField(1)
|
2021-03-26 13:38:39 +00:00
|
|
|
final String applicationKey;
|
2021-02-03 20:26:38 +00:00
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
String get encodedApiKey => encodedBackblazeKey(keyId, applicationKey);
|
2021-02-03 20:26:38 +00:00
|
|
|
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
String toString() => '$keyId: $encodedApiKey';
|
2021-02-03 20:26:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 19:36:32 +00:00
|
|
|
String encodedBackblazeKey(final String? keyId, final String? applicationKey) {
|
|
|
|
final String apiKey = '$keyId:$applicationKey';
|
|
|
|
final String encodedApiKey = base64.encode(utf8.encode(apiKey));
|
2021-02-03 20:26:38 +00:00
|
|
|
return encodedApiKey;
|
|
|
|
}
|