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

CSHARP-5065: Deserialize wrappedBytes directly instead of using RawBsonDocument in ExplicitEncryptionLibMongoCryptController.cs #1321

Merged
merged 2 commits into from
May 29, 2024

Conversation

adelinowona
Copy link
Contributor

@adelinowona adelinowona commented May 7, 2024

  • wrap uses of RawBsonDocument appropriately in using statements.

  • Switch to using BsonSerializer.Deserialize in the UnwrapValue function instead of using RawBsonDocument. This helps us since we couldn't dispose of RawBsonDocument in this case as the returned value would be disposed as well. Also avoids us having to do cloning as a remedy if we were to still use RawBsonDocument.

Just want input on whether I'm missing something here by not using RawBsonDocument

@adelinowona adelinowona requested a review from a team as a code owner May 7, 2024 21:32
@adelinowona adelinowona requested review from rstam, BorisDog and sanych-sun and removed request for a team May 7, 2024 21:32
Copy link
Member

@sanych-sun sanych-sun left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -568,8 +568,8 @@ private Guid UnwrapKeyId(RawBsonDocument wrappedKeyDocument)

private BsonValue UnwrapValue(byte[] encryptedWrappedBytes)
{
var rawDocument = new RawBsonDocument(encryptedWrappedBytes);
return rawDocument["v"];
var bsonDocument = BsonSerializer.Deserialize<BsonDocument>(encryptedWrappedBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks safe to me. I don't recall what was the motivation to use RawBsonDocument as in most cases the v value will being read completely but consumer.
Maybe @rstam has some ideas.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why a RawBsonDocument is being used here. If the goal is to deserialize the key bytes we should just do that directly.

Not sure that is the goal though.

@@ -568,8 +568,8 @@ private Guid UnwrapKeyId(RawBsonDocument wrappedKeyDocument)

private BsonValue UnwrapValue(byte[] encryptedWrappedBytes)
{
var rawDocument = new RawBsonDocument(encryptedWrappedBytes);
return rawDocument["v"];
var bsonDocument = BsonSerializer.Deserialize<BsonDocument>(encryptedWrappedBytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why a RawBsonDocument is being used here. If the goal is to deserialize the key bytes we should just do that directly.

Not sure that is the goal though.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

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

LGTM

@adelinowona adelinowona merged commit f8f1198 into mongodb:master May 29, 2024
26 of 28 checks passed
@adelinowona adelinowona deleted the csharp5065 branch May 29, 2024 19:37
@adelinowona adelinowona changed the title CSHARP-5065: Dispose RawBsonDocument in ExplicitEncryptionLibMongoCryptController.cs CSHARP-5065: Deserialize wrappedBytes directly instead of using RawBsonDocument in ExplicitEncryptionLibMongoCryptController.cs May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants