You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been using this library for a while and it worked perfectly fine. However recently I imported few more OTP accounts and one of them had spaces in secret. It lead to errors being thrown in base32Decode. I fixed it by simply removing all spaces. Maybe I should have placed spaces removal code in fromBase32 or somewhere else. Anyways, I thought that it might help someone, so here' s modified code:
/** * RFC 4648 base32 alphabet without pad. * @type {string} */constALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";/** * Converts a base32 string to an Uint8Array (RFC 4648). * @see [LinusU/base32-decode](https://github.com/LinusU/base32-decode) * @param {string} str Base32 string. * @returns {Uint8Array} Uint8Array. */constbase32Decode=(str)=>{// remove spacesstr=str.replaceAll(" ","");// Canonicalize to all upper case and remove padding if it exists.letend=str.length;while(str[end-1]==="=")--end;constcstr=(end<str.length ? str.substring(0,end) : str).toUpperCase();constbuf=newArrayBuffer(((cstr.length*5)/8)|0);constarr=newUint8Array(buf);letbits=0;letvalue=0;letindex=0;for(leti=0;i<cstr.length;i++){constidx=ALPHABET.indexOf(cstr[i]);if(idx===-1)thrownewTypeError(`Invalid character found in ${str}: ${cstr[i]}`);value=(value<<5)|idx;bits+=5;if(bits>=8){bits-=8;arr[index++]=value>>>bits;}}returnarr;};
The text was updated successfully, but these errors were encountered:
Although spaces are not allowed by the spec, I'm aware that some issuers add them to improve readability. Some programs like Bitwarden or KeePassXC are permissive and automatically remove spaces in the secret field, I think we could do the same.
I've been using this library for a while and it worked perfectly fine. However recently I imported few more OTP accounts and one of them had spaces in secret. It lead to errors being thrown in base32Decode. I fixed it by simply removing all spaces. Maybe I should have placed spaces removal code in fromBase32 or somewhere else. Anyways, I thought that it might help someone, so here' s modified code:
The text was updated successfully, but these errors were encountered: