-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate urlsafe-base64 to be internal to web-push and switch to Buffe…
…r.from (#813) Fixes #785 Co-authored-by: Dan Lee <[email protected]>
- Loading branch information
1 parent
2eb5ea2
commit de2aa16
Showing
12 changed files
with
115 additions
and
85 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Largely ported from https://github.com/RGBboy/urlsafe-base64 | ||
|
||
'use strict'; | ||
|
||
function encode(buffer) { | ||
return buffer.toString('base64') | ||
.replace(/\+/g, '-') // Convert '+' to '-' | ||
.replace(/\//g, '_') // Convert '/' to '_' | ||
.replace(/=+$/, ''); // Remove ending '=' | ||
} | ||
|
||
function decode(base64) { | ||
// Add removed at end '=' | ||
base64 += Array(5 - (base64.length % 4)).join('='); | ||
|
||
base64 = base64 | ||
.replace(/-/g, '+') // Convert '-' to '+' | ||
.replace(/_/g, '/'); // Convert '_' to '/' | ||
|
||
// change from urlsafe-base64 since new Buffer() is deprecated | ||
return Buffer.from(base64, 'base64'); | ||
} | ||
|
||
function validate(base64) { | ||
return /^[A-Za-z0-9\-_]+$/.test(base64); | ||
} | ||
|
||
module.exports = { | ||
encode: encode, | ||
decode: decode, | ||
validate: validate | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.