ente/lib/models/key_attributes.dart

103 lines
3.2 KiB
Dart
Raw Normal View History

import 'dart:convert';
class KeyAttributes {
final String kekSalt;
final String encryptedKey;
final String keyDecryptionNonce;
final String publicKey;
final String encryptedSecretKey;
final String secretKeyDecryptionNonce;
final int? memLimit;
final int? opsLimit;
final String? masterKeyEncryptedWithRecoveryKey;
final String? masterKeyDecryptionNonce;
2022-12-30 10:03:50 +00:00
final String? recoveryKeyEncryptedWithMasterKey;
final String? recoveryKeyDecryptionNonce;
2020-09-30 18:31:04 +00:00
KeyAttributes(
this.kekSalt,
this.encryptedKey,
this.keyDecryptionNonce,
this.publicKey,
this.encryptedSecretKey,
this.secretKeyDecryptionNonce,
this.memLimit,
this.opsLimit,
2021-03-29 14:59:37 +00:00
this.masterKeyEncryptedWithRecoveryKey,
this.masterKeyDecryptionNonce,
this.recoveryKeyEncryptedWithMasterKey,
this.recoveryKeyDecryptionNonce,
2020-09-30 18:31:04 +00:00
);
Map<String, dynamic> toMap() {
return {
'kekSalt': kekSalt,
'encryptedKey': encryptedKey,
'keyDecryptionNonce': keyDecryptionNonce,
'publicKey': publicKey,
'encryptedSecretKey': encryptedSecretKey,
'secretKeyDecryptionNonce': secretKeyDecryptionNonce,
'memLimit': memLimit,
'opsLimit': opsLimit,
2021-03-29 14:59:37 +00:00
'masterKeyEncryptedWithRecoveryKey': masterKeyEncryptedWithRecoveryKey,
'masterKeyDecryptionNonce': masterKeyDecryptionNonce,
'recoveryKeyEncryptedWithMasterKey': recoveryKeyEncryptedWithMasterKey,
'recoveryKeyDecryptionNonce': recoveryKeyDecryptionNonce,
};
}
factory KeyAttributes.fromMap(Map<String, dynamic> map) {
return KeyAttributes(
2020-09-30 18:31:04 +00:00
map['kekSalt'],
map['encryptedKey'],
map['keyDecryptionNonce'],
map['publicKey'],
map['encryptedSecretKey'],
map['secretKeyDecryptionNonce'],
map['memLimit'],
map['opsLimit'],
2021-03-29 14:59:37 +00:00
map['masterKeyEncryptedWithRecoveryKey'],
map['masterKeyDecryptionNonce'],
map['recoveryKeyEncryptedWithMasterKey'],
map['recoveryKeyDecryptionNonce'],
);
}
String toJson() => json.encode(toMap());
factory KeyAttributes.fromJson(String source) =>
KeyAttributes.fromMap(json.decode(source));
2021-03-29 14:59:37 +00:00
KeyAttributes copyWith({
String? kekSalt,
String? encryptedKey,
String? keyDecryptionNonce,
String? publicKey,
String? encryptedSecretKey,
String? secretKeyDecryptionNonce,
int? memLimit,
int? opsLimit,
String? masterKeyEncryptedWithRecoveryKey,
String? masterKeyDecryptionNonce,
String? recoveryKeyEncryptedWithMasterKey,
String? recoveryKeyDecryptionNonce,
2021-03-29 14:59:37 +00:00
}) {
return KeyAttributes(
kekSalt ?? this.kekSalt,
encryptedKey ?? this.encryptedKey,
keyDecryptionNonce ?? this.keyDecryptionNonce,
publicKey ?? this.publicKey,
encryptedSecretKey ?? this.encryptedSecretKey,
secretKeyDecryptionNonce ?? this.secretKeyDecryptionNonce,
memLimit ?? this.memLimit,
opsLimit ?? this.opsLimit,
masterKeyEncryptedWithRecoveryKey ??
this.masterKeyEncryptedWithRecoveryKey,
masterKeyDecryptionNonce ?? this.masterKeyDecryptionNonce,
recoveryKeyEncryptedWithMasterKey ??
this.recoveryKeyEncryptedWithMasterKey,
recoveryKeyDecryptionNonce ?? this.recoveryKeyDecryptionNonce,
);
}
}