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

Explicit support for optional field types #92

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

paragonie-security
Copy link
Contributor

You can now define optional fields. These do not encrypt when NULL is provided as a value. Instead, they become an unencrypted NULL.

EncryptedRow:

  • foo, OptionalText
  • bar, OptionalText

Plaintext: ['foo' => 'abc', 'bar' => null]
Ciphertext: ['foo' => /* encrypted */, 'bar' => null]

These are called "optional" types to disambiguate with NULL support. This matters because Boolean fields always supported NULL under-the-hood.

Types Mapping with Optional

  • Boolean:
    • (true) -> (ciphertext)
    • (false) -> (ciphertext)
    • (null) -> (ciphertext)
  • Integer:
    • (int) -> (ciphertext)
    • (null) -> TypeError
  • Float:
    • (float) -> (ciphertext)
    • (null) -> TypeError
  • JSON:
    • (json) -> (ciphertext)
    • (null) -> TypeError
  • Text:
    • (string) -> (ciphertext)
    • (null) -> TypeError
  • OptionalBoolean:
    • (true) -> (ciphertext)
    • (false) -> (ciphertext)
    • (null) -> (null)
  • OptionalInteger:
    • (int) -> (ciphertext)
    • (null) -> (null)
  • OptionalFloat:
    • (float) -> (ciphertext)
    • (null) -> (null)
  • OptionalJSON:
    • (json) -> (ciphertext)
    • (null) -> (null)
  • OptionalText:
    • (string) -> (ciphertext)
    • (null) -> (null)

You can now define optional fields. These do not encrypt when NULL is provided as a value. Instead, they become an unencrypted NULL.

EncryptedRow:
  - foo, OptionalText
  - bar, OptionalText

Plaintext: ['foo' => 'abc', 'bar' => null]
Ciphertext: ['foo' => /* encrypted */, 'bar' => null]

These are called "optional" types to disambiguate with NULL support. This matters because Boolean fields always supported NULL under-the-hood.

## Types Mapping with Optional

- Boolean:
  - (true) -> (ciphertext)
  - (false) -> (ciphertext)
  - (null) -> (ciphertext)
- Integer:
  - (int) -> (ciphertext)
  - (null) -> TypeError
- Float:
  - (float) -> (ciphertext)
  - (null) -> TypeError
- JSON:
  - (json) -> (ciphertext)
  - (null) -> TypeError
- Text:
  - (string) -> (ciphertext)
  - (null) -> TypeError
- OptionalBoolean:
  - (true) -> (ciphertext)
  - (false) -> (ciphertext)
  - (null) -> (null)
- OptionalInteger:
  - (int) -> (ciphertext)
  - (null) -> (null)
- OptionalFloat:
  - (float) -> (ciphertext)
  - (null) -> (null)
- OptionalJSON:
  - (json) -> (ciphertext)
  - (null) -> (null)
- OptionalText:
  - (string) -> (ciphertext)
  - (null) -> (null)
@paragonie-security paragonie-security merged commit 92aac4c into master Jul 28, 2023
3 checks passed
@paragonie-security paragonie-security deleted the support-old-null-acceptance branch July 28, 2023 19:32
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.

1 participant