From 8cfccf3747881745a389e88f61e6617a5d7acaa4 Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Tue, 15 Oct 2024 14:09:47 -0500 Subject: [PATCH] more readable bits --- src/status-list/StatusList/Bitstring.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/status-list/StatusList/Bitstring.ts b/src/status-list/StatusList/Bitstring.ts index d67aead..698216e 100644 --- a/src/status-list/StatusList/Bitstring.ts +++ b/src/status-list/StatusList/Bitstring.ts @@ -109,9 +109,21 @@ export class Bitstring { assert.isNumber(position, 'position') const { length, leftToRightIndexing } = this const { index, bit } = _parsePosition(position, length, leftToRightIndexing) - return !!(this.bits[index] & bit) + const actualBitSet = this.bits[index] & bit % 8 + // Let bitstring be a list of bits with a minimum size of 16KB, where each bit is initialized to 0 (zero). + // .... + // When a single bit specifies a status, such as "revoked" or "suspended", + // then that status is expected to be true when the bit is set (1) and false when unset (0). + if (actualBitSet === 1) { + return true + } + if (actualBitSet === 0) { + return false + } + throw new Error('Invalid bit') } + async encodeBits() { return base64url.encode(gzip(this.bits)) } @@ -146,6 +158,10 @@ function _parsePosition( const index = Math.floor(position / 8) const rem = position % 8 const shift = leftToRightIndexing ? 7 - rem : rem - const bit = 1 << shift + + // When a single bit specifies a status, such as "revoked" or "suspended", + // then that status is expected to be true when the bit is set (1) and false when unset (0). + const bit = (1 << shift) + // the real bit value is bit % 8 return { index, bit } }