diff --git a/packages/jwt-status-list/src/status-list.ts b/packages/jwt-status-list/src/status-list.ts index 8de5871..aa87c84 100644 --- a/packages/jwt-status-list/src/status-list.ts +++ b/packages/jwt-status-list/src/status-list.ts @@ -5,7 +5,7 @@ import type { BitsPerStatus } from './types'; * StatusListManager is a class that manages a list of statuses with variable bit size. */ export class StatusList { - private statusList: number[]; + private _statusList: number[]; private bitsPerStatus: BitsPerStatus; private totalStatuses: number; @@ -26,11 +26,18 @@ export class StatusList { ); } } - this.statusList = statusList; + this._statusList = statusList; this.bitsPerStatus = bitsPerStatus; this.totalStatuses = statusList.length; } + /** + * Get the status list. + */ + get statusList(): number[] { + return this._statusList; + } + /** * Get the number of statuses. * @returns @@ -42,13 +49,12 @@ export class StatusList { /** * Get the status at a specific index. * @param index - * @returns */ getStatus(index: number): number { if (index < 0 || index >= this.totalStatuses) { throw new Error('Index out of bounds'); } - return this.statusList[index]; + return this._statusList[index]; } /** @@ -60,12 +66,11 @@ export class StatusList { if (index < 0 || index >= this.totalStatuses) { throw new Error('Index out of bounds'); } - this.statusList[index] = value; + this._statusList[index] = value; } /** * Compress the status list. - * @returns */ compressStatusList(): string { const byteArray = this.encodeStatusList(); @@ -77,7 +82,6 @@ export class StatusList { * Decompress the compressed status list and return a new StatusList instance. * @param compressed * @param bitsPerStatus - * @returns */ static decompressStatusList( compressed: string, @@ -113,7 +117,7 @@ export class StatusList { let bitIndex = 0; let currentByte = ''; for (let i = 0; i < this.totalStatuses; i++) { - const status = this.statusList[i]; + const status = this._statusList[i]; // Place bits from status into currentByte, starting from the most significant bit. currentByte = status.toString(2).padStart(numBits, '0') + currentByte; bitIndex += numBits; diff --git a/packages/jwt-status-list/src/test/status-list.spec.ts b/packages/jwt-status-list/src/test/status-list.spec.ts index cb9eaa7..6a61e56 100644 --- a/packages/jwt-status-list/src/test/status-list.spec.ts +++ b/packages/jwt-status-list/src/test/status-list.spec.ts @@ -26,9 +26,14 @@ describe('StatusList', () => { const manager = new StatusList(status, 1); const encoded = manager.compressStatusList(); expect(encoded).toBe('eNrbuRgAAhcBXQ'); - const l = StatusList.decompressStatusList(encoded, 1); + const list = StatusList.decompressStatusList(encoded, 1); for (let i = 0; i < status.length; i++) { - expect(l.getStatus(i)).toBe(status[i]); + expect(list.getStatus(i)).toBe(status[i]); + } + + //get the whole list and check if it is equal + for (let i = 0; i < list.statusList.length; i++) { + expect(list.statusList[i]).toBe(status[i]); } });