Skip to content

Commit b2b17b3

Browse files
authored
Update string conversion (#6162)
Node 20 now validates the type of input parameters for the `sign` API and our current implementation is throwing in our test environment as the buffer we are passing is the wrong type. This PR addresses this error.
1 parent be568d5 commit b2b17b3

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Update string conversion function",
4+
"packageName": "@azure/msal-browser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

lib/msal-browser/src/crypto/CryptoOps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class CryptoOps implements ICrypto {
224224
const tokenString = `${encodedShrHeader}.${encodedPayload}`;
225225

226226
// Sign token
227-
const tokenBuffer = BrowserStringUtils.stringToArrayBuffer(tokenString);
227+
const tokenBuffer = BrowserStringUtils.stringToUtf8Arr(tokenString);
228228
const signatureBuffer = await this.browserCrypto.sign(
229229
cachedKeyPair.privateKey,
230230
tokenBuffer

lib/msal-browser/src/utils/BrowserStringUtils.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class BrowserStringUtils {
3434
? 5
3535
: 6;
3636
}
37-
37+
3838
const aBytes = new Uint8Array(nArrLen);
3939

4040
/* transcription... */
@@ -80,19 +80,6 @@ export class BrowserStringUtils {
8080
return aBytes;
8181
}
8282

83-
/**
84-
* Converst string to ArrayBuffer
85-
* @param dataString
86-
*/
87-
static stringToArrayBuffer(dataString: string): ArrayBuffer {
88-
const data = new ArrayBuffer(dataString.length);
89-
const dataView = new Uint8Array(data);
90-
for (let i: number = 0; i < dataString.length; i++) {
91-
dataView[i] = dataString.charCodeAt(i);
92-
}
93-
return data;
94-
}
95-
9683
/**
9784
* Converts Uint8Array to a string
9885
* @param aBytes

0 commit comments

Comments
 (0)