CryptUtilsStringArray.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { inject, injectable } from 'inversify';
  2. import { ServiceIdentifiers } from '../container/ServiceIdentifiers';
  3. import { ICryptUtilsStringArray } from '../interfaces/utils/ICryptUtilsStringArray';
  4. import { IRandomGenerator } from '../interfaces/utils/IRandomGenerator';
  5. import { base64alphabetSwapped } from '../constants/Base64AlphabetSwapped';
  6. import { CryptUtils } from './CryptUtils';
  7. @injectable()
  8. export class CryptUtilsStringArray extends CryptUtils implements ICryptUtilsStringArray {
  9. /**
  10. * @type {string}
  11. */
  12. protected override readonly base64Alphabet: string = base64alphabetSwapped;
  13. /**
  14. * @param {IRandomGenerator} randomGenerator
  15. */
  16. public constructor (
  17. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator
  18. ) {
  19. super(randomGenerator);
  20. }
  21. /**
  22. * Removes base64 encoded string without padding characters and with swapped alphabet
  23. *
  24. * @param {string} string
  25. * @returns {string}
  26. */
  27. public override btoa (string: string): string {
  28. const output = super.btoa(string);
  29. return output.replace(/=+$/, '');
  30. }
  31. }