Skip to content

Commit

Permalink
more readable bits
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Oct 15, 2024
1 parent b8b1a17 commit 8cfccf3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/status-list/StatusList/Bitstring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 }
}

0 comments on commit 8cfccf3

Please sign in to comment.