Skip to content

fix: BYTES_PER_KEY value #193

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

Merged
merged 11 commits into from
Sep 6, 2019
19 changes: 17 additions & 2 deletions modules/serialize/src/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,23 @@ Object.freeze(SequenceIdentifier)
export enum Maximum {
// Maximum number of messages which are allowed to be encrypted under a single cached data key
MESSAGES_PER_KEY = 2 ** 32, // eslint-disable-line no-unused-vars
// Maximum number of bytes which are allowed to be encrypted under a single cached data key
BYTES_PER_KEY = 2 ** 63 - 1, // eslint-disable-line no-unused-vars
/* Maximum number of bytes which are allowed to be encrypted under a single data key
* The _real_ maximum is 2 ** 63 - 1,
* However Javascript can only perform safe operations on values
* up to Number.MAX_SAFE_INTEGER === 9007199254740991 === 2 ** 53 - 1.
* e.g
* Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2 => true
* Number.MAX_SAFE_INTEGER + 1 > Number.MAX_SAFE_INTEGER + 2 => false
* Number.MAX_SAFE_INTEGER + 1 < Number.MAX_SAFE_INTEGER + 2 => false
*
* This means that after 2 ** 53 - 1 the process of accumulating a byte count
* will never yield an accurate comparison and so, never halt.
*
* The choice here to use 2 ** 53 - 1 instead of Number.MAX_SAFE_INTEGER is deliberate.
* This is because in the future Number.MAX_SAFE_INTEGER could be raised to 2 ** 66
* or some value larger 2 ** 63.
*/
BYTES_PER_KEY = 2 ** 53 - 1, // eslint-disable-line no-unused-vars
// Maximum number of frames allowed in one message as defined in specification
FRAME_COUNT = 2 ** 32 - 1, // eslint-disable-line no-unused-vars
// Maximum bytes allowed in a single frame as defined in specification
Expand Down