Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

import 'dart:convert';
import "package:pointycastle/export.dart";
import '/utils/encryption/crypto_utils.dart';
class Friend{
String id;
String userId;
String friendId;
String friendIdDecrypted;
String acceptedAt;
Friend({
required this.id,
required this.userId,
required this.friendId,
required this.friendIdDecrypted,
required this.acceptedAt,
});
factory Friend.fromJson(Map<String, dynamic> json, RSAPrivateKey privKey) {
var friendIdDecrypted = CryptoUtils.rsaDecrypt(
base64.decode(json['friend_id']),
privKey,
);
return Friend(
id: json['id'],
userId: json['user_id'],
friendId: json['friend_id'],
friendIdDecrypted: String.fromCharCodes(friendIdDecrypted),
acceptedAt: json['accepted_at'],
);
}
@override
String toString() {
return '''
id: $id
userId: $userId,
friendId: $friendId,
friendIdDecrypted: $friendIdDecrypted,
accepted_at: $acceptedAt,
''';
}
Map<String, dynamic> toMap() {
return {
'id': id,
'user_id': userId,
'friend_id': friendId,
'friend_id_decrypted': friendIdDecrypted,
'accepted_at': acceptedAt,
};
}
}