PLangHQ / plang

The code repository from plang programming language
GNU Lesser General Public License v2.1
51 stars 5 forks source link

Timeout/Usage limitation on variables #50

Open ingig opened 2 months ago

ingig commented 2 months ago

I noticed when debugging an app that reads private key from a file, it like this

- read key.txt into %privateKey%
- / use the %privateKey%

That the %privateKey% variable still exists, as it should, with the private key data inside. So the whole time the application is running, it will be in memory, which is not good for security.

The way to solve this to day is to

- read key.txt into %privateKey%
- / use the %privateKey%
- set %privateKey% = null

But I had an idea of Timeout / Usage for a variable, that means that a variable would expire after certain amount of ms or after being used certain amount of times

So why not define the %privateKey% variable like this,

for usage

- read key.txt into %privateKey%, expire after 1st usage
- / use the %privateKey%

or if you like timeout

- read key.txt into %privateKey%, expire after 1 min
- / use the %privateKey%

Then the plang language would clean up this variable.

It would also allow the language/IDE to suggest to add usage/timeout if it sees the variable is only used once or if it's called private key or being used as one.

This would mean breaking current code, as return in Program function is primatives, list, dict. But it would need to be some Variable type storing, name, value, timeout, usage properties.