summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src/helpers')
-rw-r--r--packages/browser/src/helpers/toBase64String.test.ts15
-rw-r--r--packages/browser/src/helpers/toBase64String.ts3
-rw-r--r--packages/browser/src/helpers/toUint8Array.ts4
3 files changed, 18 insertions, 4 deletions
diff --git a/packages/browser/src/helpers/toBase64String.test.ts b/packages/browser/src/helpers/toBase64String.test.ts
new file mode 100644
index 0000000..bbcb11b
--- /dev/null
+++ b/packages/browser/src/helpers/toBase64String.test.ts
@@ -0,0 +1,15 @@
+import toBase64String from './toBase64String';
+
+import toUint8Array from './toUint8Array';
+
+test('should convert a Buffer to a string with a length that is a multiple of 4', () => {
+ const base64 = toBase64String(Buffer.from('123456', 'ascii'));
+
+ expect(base64.length % 4).toEqual(0);
+});
+
+test('should convert a Uint8Array to a string with a length that is a multiple of 4', () => {
+ const base64 = toBase64String(toUint8Array('123456'));
+
+ expect(base64.length % 4).toEqual(0);
+});
diff --git a/packages/browser/src/helpers/toBase64String.ts b/packages/browser/src/helpers/toBase64String.ts
index 8234002..9c949be 100644
--- a/packages/browser/src/helpers/toBase64String.ts
+++ b/packages/browser/src/helpers/toBase64String.ts
@@ -4,6 +4,5 @@ export default function toBase64String(buffer: ArrayBuffer): string {
// TODO: Make sure converting buffer to Uint8Array() is correct
return base64js.fromByteArray(new Uint8Array(buffer))
.replace(/\+/g, "-")
- .replace(/\//g, "_")
- .replace(/=/g, "");
+ .replace(/\//g, "_");
}
diff --git a/packages/browser/src/helpers/toUint8Array.ts b/packages/browser/src/helpers/toUint8Array.ts
index a807a88..ed4aa5d 100644
--- a/packages/browser/src/helpers/toUint8Array.ts
+++ b/packages/browser/src/helpers/toUint8Array.ts
@@ -1,6 +1,6 @@
/**
- * A helper method to convert a string sent from the server to a Uint8Array the authenticator will
- * expect.
+ * A helper method to convert an arbitrary string sent from the server to a Uint8Array the
+ * authenticator will expect.
*/
export default function toUint8Array(value: string): Uint8Array {
return Uint8Array.from(value, c => c.charCodeAt(0));