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

  1. import 'dart:convert';
  2. import "package:pointycastle/export.dart";
  3. import '/utils/encryption/crypto_utils.dart';
  4. class Friend{
  5. String id;
  6. String userId;
  7. String friendId;
  8. String friendIdDecrypted;
  9. String acceptedAt;
  10. Friend({
  11. required this.id,
  12. required this.userId,
  13. required this.friendId,
  14. required this.friendIdDecrypted,
  15. required this.acceptedAt,
  16. });
  17. factory Friend.fromJson(Map<String, dynamic> json, RSAPrivateKey privKey) {
  18. var friendIdDecrypted = CryptoUtils.rsaDecrypt(
  19. base64.decode(json['friend_id']),
  20. privKey,
  21. );
  22. return Friend(
  23. id: json['id'],
  24. userId: json['user_id'],
  25. friendId: json['friend_id'],
  26. friendIdDecrypted: String.fromCharCodes(friendIdDecrypted),
  27. acceptedAt: json['accepted_at'],
  28. );
  29. }
  30. @override
  31. String toString() {
  32. return '''
  33. id: $id
  34. userId: $userId,
  35. friendId: $friendId,
  36. friendIdDecrypted: $friendIdDecrypted,
  37. accepted_at: $acceptedAt,
  38. ''';
  39. }
  40. Map<String, dynamic> toMap() {
  41. return {
  42. 'id': id,
  43. 'user_id': userId,
  44. 'friend_id': friendId,
  45. 'friend_id_decrypted': friendIdDecrypted,
  46. 'accepted_at': acceptedAt,
  47. };
  48. }
  49. }