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

Suggestion: Allow dynamic variable types in datum #135

Closed
koenniem opened this issue Dec 2, 2020 · 4 comments
Closed

Suggestion: Allow dynamic variable types in datum #135

koenniem opened this issue Dec 2, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@koenniem
Copy link

koenniem commented Dec 2, 2020

Context

I am making my own PrivacySchema and one of its purposes is that needs to encrypt GPS coordinates since these are highly identifying data.

Motivation

Such a locationAnonymizer (using the flutter_sodium library would look like this

  /// A [LocationDatum] anonymizer function.
  Datum locationAnonymizer(Datum datum) {
    assert(datum is LocationDatum);
    LocationDatum ld = datum as LocationDatum;
    return ld..longitude = Sodium.bin2hex(SealedBox.sealString(ld.longitude, pubkey));
  }

However, this does not work as ld..longitude is a double (they are coordinates after all) while the encrypted value is a string.

Attempted solutions

I've some up with several solutions so far:

  • Adding an extra string variable to LocationDatum. However, this variable would then not be used in other functions so it's essentially pointless.
  • Overriding the LocationDatum myself to change longitude from a double to a string (using toString()). However, methods cannot be override outside their library.
  • Binarizing the encrypted string. As expected, this led to a double overflow.

Proposed solution

In the respective packages with the Datums, change types from double to dynamic (or to string altogether) to allow for exactly this behaviour. I'm not sure if there are any downside for this other than giving in to a more loose typed way of programming.

@koenniem koenniem changed the title Suggestion: Allow dynamic Suggestion: Allow dynamic variable types in datum Dec 2, 2020
@bardram bardram added the enhancement New feature or request label Dec 7, 2020
@bardram bardram self-assigned this Dec 7, 2020
@bardram
Copy link
Contributor

bardram commented Dec 7, 2020

hm... will think about this - after all, I'm an old-school OOP programmer, so loosely type checking works against my basic instincts ;-)

I wonder what other problems this might create.... But will make an experiment.

@koenniem
Copy link
Author

koenniem commented Dec 7, 2020

Yes, I understand your aversion of giving in to loose typing. I'm not a fan myself either (JavaScript pstsd).

So if you find this use case something worth taking into account, and there is no better solution, and there are no adverse effects, I'd say this is the way to go.

@bardram
Copy link
Contributor

bardram commented Dec 17, 2020

I will try to release this as part of version 0.11.0.

However, it has a consequence on the JSON serialization. For example, if double values are used, the json look like this:

{
  "id": "47bfabd0-40a4-11eb-bbbe-ef47445b6df8",
  "timestamp": "2020-12-17T20:13:08.746280Z",
  "latitude": 3.34224,
  "longitude": 12.23342,
  "altitude": 124.2134235
 }

But when "encrypting", resulting in a string, it looks like:

{
  "id": "47bfabd0-40a4-11eb-bbbe-ef47445b6df8",
  "timestamp": "2020-12-17T20:13:08.746280Z",
  "latitude": 3.34224,
  "longitude": 12.23342,
  "altitude": "encrypted value"
 }

So - whatever is used for reading the json need to be able to handle that the attributes can both be numerical and strings.

bardram added a commit that referenced this issue Dec 17, 2020
@bardram bardram closed this as completed Dec 17, 2020
@koenniem
Copy link
Author

For me that's okay. I'm working on an R package for reading in CARP data (still in a very early stage) and any type would work fine there (even mixed, sometimes double sometimes string).

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

No branches or pull requests

2 participants