Skip to content

Conversation

@paulinevos
Copy link
Contributor

Prepends iue for In-Use Encryption to platform metadata string in MongoDB handshake. This will allow for easier detection of encryption usage in higher level libraries.

This PR also extracts the options array into DriverOptions in order to simplify testing the I/O of options as we do quite a bit of transformation on them.

@paulinevos paulinevos requested a review from a team as a code owner December 16, 2025 13:45
@paulinevos paulinevos requested a review from GromNaN December 16, 2025 13:45
@paulinevos paulinevos force-pushed the 1728-encryption-usage branch from 781e640 to 130f2e6 Compare December 16, 2025 13:55
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

This PR also extracts the options array into DriverOptions in order to simplify testing the I/O of options as we do quite a bit of transformation on them.

This sounds like a good idea, and this has no impact on users, since these classes are internal and cannot be accessed from public APIs.

But I question whether an undefined and a null option have the same meaning in this context.

public readonly Encoder $builderEncoder,
public readonly array $autoEncryption,
public readonly array $driver,
private readonly array $miscOptions,
Copy link
Member

Choose a reason for hiding this comment

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

Should it be more specific.
Not $managerOptions because $autoEncryption is a manager option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured no, as if we get more specific we are tying it more to server implementation. I figured that as much as possible we want to pass options as is. In my mind it's just any options that we aren't transforming in some way.


return (new self(
typeMap: $options[self::KEY_TYPE_MAP],
builderEncoder: $options[self::KEY_BUILDER_ENCODER] ?? new BuilderEncoder(),
Copy link
Member

Choose a reason for hiding this comment

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

You don't validate that builderEncoder is an instance of BuilderEncoder before using it for a typed parameter. This will result in an unspecific TypeError.

Copy link
Contributor Author

@paulinevos paulinevos Dec 16, 2025

Choose a reason for hiding this comment

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

I validate that it's an instance of Encoder in ensureValidArrayOptions. There's a test case for it too

@paulinevos paulinevos force-pushed the 1728-encryption-usage branch 2 times, most recently from b5c3b2d to 8b56aa2 Compare December 16, 2025 16:23
So we can unit test options, as we're transforming some of the options
that are passed

stuff
Sending extra metadata in the handshake will allow us to detect when
encryption is enabled. `iue` for In-Use Ecnryption was chosen to save
bytes (as metadata will be truncated if it exceeds byte limit)
@paulinevos paulinevos force-pushed the 1728-encryption-usage branch from 8b56aa2 to ddeaac1 Compare December 16, 2025 16:27
@paulinevos
Copy link
Contributor Author

But I question whether an undefined and a null option have the same meaning in this context.

There were some test cases re: this in ClientTest so I ensured that those passed and that that behavior didn't change. As far as other potential nullables, I'm not too sure...

@paulinevos paulinevos requested a review from GromNaN December 16, 2025 16:30
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Tests are failing. Do you need help for the spec tests?

'autoEncryption' => $this->autoEncryption,
'driver' => $this->driver,
] + $this->miscOptions,
fn ($option) => $option !== null,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn ($option) => $option !== null,
static fn ($option) => $option !== null,

Comment on lines +155 to +162
return new self(
typeMap: $this->typeMap,
builderEncoder: $this->builderEncoder,
autoEncryption: $this->autoEncryption,
driver: $mergedDriver,
miscOptions: $this->miscOptions,
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Creating a second instance of DriverOptions does not seem efficient to me, especially since this method is always called in the factory. A simple assignment is enough.

Suggested change
return new self(
typeMap: $this->typeMap,
builderEncoder: $this->builderEncoder,
autoEncryption: $this->autoEncryption,
driver: $mergedDriver,
miscOptions: $this->miscOptions,
);
}
$this->driver = $mergedDriver;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is that then I'd have to change the readonly and visibility (which is fine, I can make it private I guess. Nothing is directly accessing it as of now)

Copy link
Member

Choose a reason for hiding this comment

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

If you don't use CPP for $driver, you can alter its value before setting the property.


public static function fromArray(array $options): self
{
$options += ['typeMap' => self::DEFAULT_TYPE_MAP];
Copy link
Member

Choose a reason for hiding this comment

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

Should this be self::KEY_TYPE_MAP?

Suggested change
$options += ['typeMap' => self::DEFAULT_TYPE_MAP];
$options += ['self::KEY_TYPE_MAP' => self::DEFAULT_TYPE_MAP];

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.

3 participants