mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
buffer: add base64url encoding option
PR-URL: https://github.com/nodejs/node/pull/36952 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
9e7d1a1c24
commit
f8ab632d56
17 changed files with 306 additions and 120 deletions
|
@ -646,6 +646,20 @@ const encodingOps = {
|
|||
encodingsMap.base64,
|
||||
dir)
|
||||
},
|
||||
base64url: {
|
||||
encoding: 'base64url',
|
||||
encodingVal: encodingsMap.base64url,
|
||||
byteLength: (string) => base64ByteLength(string, string.length),
|
||||
write: (buf, string, offset, len) =>
|
||||
buf.base64urlWrite(string, offset, len),
|
||||
slice: (buf, start, end) => buf.base64urlSlice(start, end),
|
||||
indexOf: (buf, val, byteOffset, dir) =>
|
||||
indexOfBuffer(buf,
|
||||
fromStringFast(val, encodingOps.base64url),
|
||||
byteOffset,
|
||||
encodingsMap.base64url,
|
||||
dir)
|
||||
},
|
||||
hex: {
|
||||
encoding: 'hex',
|
||||
encodingVal: encodingsMap.hex,
|
||||
|
@ -702,6 +716,11 @@ function getEncodingOps(encoding) {
|
|||
if (encoding === 'hex' || StringPrototypeToLowerCase(encoding) === 'hex')
|
||||
return encodingOps.hex;
|
||||
break;
|
||||
case 9:
|
||||
if (encoding === 'base64url' ||
|
||||
StringPrototypeToLowerCase(encoding) === 'base64url')
|
||||
return encodingOps.base64url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue