Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SG-10] Refactor Cipher data model #76

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lizard-boy
Copy link

@lizard-boy lizard-boy commented Oct 19, 2024

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Draft refactor of the cipher data model. Replaces the data with a serialized instance of EncObject which is controlled by the clients.

Code changes

  • file.ext: Description of what was changed and why

Before you submit

  • I have checked for formatting errors (dotnet tool run dotnet-format --check) (required)
  • If making database changes - I have also updated Entity Framework queries and/or migrations
  • I have added unit tests where it makes sense to do so (encouraged but not required)
  • This change requires a documentation update (notify the documentation team)
  • This change has particular deployment requirements (notify the DevOps team)
    …itional-item-types

Greptile Summary

This pull request introduces significant changes to the cipher data model, focusing on improved flexibility and encryption handling. Here's a concise summary of the major changes:

  • Introduced new EncObject class for enhanced encryption control
  • Refactored CipherRequestModel and CipherResponseModel to accommodate EncObject
  • Reorganized cipher-related classes into a dedicated Cipher folder
  • Modified CipherType enum to prepare for potential future additions
  • Updated CipherAttachment class with new properties and nested MetaData class
  • Adjusted inheritance structure for various cipher data classes

These changes aim to provide more flexibility in handling different cipher types and improve the overall structure of the cipher data model. However, careful consideration should be given to data consistency and backward compatibility during implementation.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14 file(s) reviewed, 15 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 89 to +91
default:
throw new ArgumentException("Unsupported type: " + nameof(Type) + ".");
existingCipher.Data = JsonSerializer.Serialize(Data, JsonHelpers.IgnoreWritingNull);
break;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This default case allows for custom cipher types, but ensure that proper validation and type checking are implemented to prevent misuse or data corruption.

@@ -52,13 +52,19 @@ public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bo
Identity = new CipherIdentityModel(identityData);
break;
default:
throw new ArgumentException("Unsupported " + nameof(Type) + ".");
var customData = JsonSerializer.Deserialize<EncObject>(cipher.Data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Ensure that JsonSerializer.Deserialize can handle null cipher.Data

Comment on lines +61 to +67
if (cipherData != null)
{
Name = cipherData.Name;
Notes = cipherData.Notes;
Fields = cipherData.Fields?.Select(f => new CipherFieldModel(f));
PasswordHistory = cipherData.PasswordHistory?.Select(ph => new CipherPasswordHistoryModel(ph));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This block may leave Name, Notes, Fields, and PasswordHistory uninitialized for custom types

{
public class EncObject
{
public EncryptionType Type { get; set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider adding XML documentation for each property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants