Skip to content

Commit

Permalink
fix(console): url safe base64 to array buffer (#6019)
Browse files Browse the repository at this point in the history
fix: console base64 to array buffer

Co-authored-by: Livio Spring <livio.a@gmail.com>
  • Loading branch information
peintnermax and livio-a committed Jun 13, 2023
1 parent 5693e40 commit e39d1b7
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions console/src/app/pages/users/user-detail/u2f-util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
export function _base64ToArrayBuffer(base64: string): any {
const binaryString = atob(base64);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
export function _base64ToArrayBuffer(thing: any) {
if (typeof thing === 'string') {
// base64url to base64
thing = thing.replace(/-/g, '+').replace(/_/g, '/');

// base64 to Uint8Array
var str = window.atob(thing);
var bytes = new Uint8Array(str.length);
for (var i = 0; i < str.length; i++) {
bytes[i] = str.charCodeAt(i);
}
thing = bytes;
}

// Array to Uint8Array
if (Array.isArray(thing)) {
thing = new Uint8Array(thing);
}

// Uint8Array to ArrayBuffer
if (thing instanceof Uint8Array) {
thing = thing.buffer;
}

// error if none of the above worked
if (!(thing instanceof ArrayBuffer)) {
throw new TypeError('could not coerce to ArrayBuffer');
}

return thing;
}

1 comment on commit e39d1b7

@vercel
Copy link

@vercel vercel bot commented on e39d1b7 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./

zitadel-docs.vercel.app
docs-git-main-zitadel.vercel.app
docs-zitadel.vercel.app

Please sign in to comment.