forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse data URIs in JS to resolve cross-environment and CSP issues (em…
- Loading branch information
Showing
11 changed files
with
245 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Simplified BSD License: | ||
|
||
Copyright (c) 2017, Cyph, Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
--- | ||
|
||
Copyright (c) 2015-2017 | ||
Ahmad Ben Mrad <batikhsouri at gmail dot org> | ||
Frank Denis <j at pureftpd dot org> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
--- | ||
|
||
Base64 <-> Uint8Array conversion tools harvested from MDN | ||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding |
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,21 @@ | ||
all: | ||
rm -rf dist tmp 2> /dev/null | ||
mkdir dist tmp | ||
|
||
wget https://raw.githubusercontent.com/jedisct1/libsodium.js/d4fcfd5/wrapper/wrap-template.js -O tmp/wrap-template.js | ||
|
||
cat pre.js > tmp/sodiumutil.js | ||
cat tmp/wrap-template.js | tr '\n' '☁' | perl -pe 's/.*Codecs(.*?)Memory management.*/\1/g' | tr '☁' '\n' >> tmp/sodiumutil.js | ||
echo >> tmp/sodiumutil.js | ||
cat tmp/wrap-template.js | tr '\n' ' ' | perl -pe 's/\s+/ /g' | perl -pe 's/.*(function memcmp.*?)\s+function.*/\1/g' >> tmp/sodiumutil.js | ||
echo >> tmp/sodiumutil.js | ||
cat tmp/wrap-template.js | tr '\n' ' ' | perl -pe 's/\s+/ /g' | perl -pe 's/.*(function memzero.*?)\s+function.*/\1/g' >> tmp/sodiumutil.js | ||
echo >> tmp/sodiumutil.js | ||
cat post.js >> tmp/sodiumutil.js | ||
|
||
uglifyjs tmp/sodiumutil.js -cmo dist/sodiumutil.js | ||
|
||
rm -rf tmp | ||
|
||
clean: | ||
rm -rf dist tmp |
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,5 @@ | ||
# sodiumutil | ||
|
||
## Overview | ||
|
||
Pulls out some useful functions from libsodium.js. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "sodiumutil", | ||
"version": "2.0.1", | ||
"description": "Pulls out some useful functions from libsodium.js", | ||
"main": "dist/sodiumutil.js", | ||
"types": "./sodiumutil.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/cyph/sodiumutil.git" | ||
}, | ||
"keywords": ["cryptography"], | ||
"author": "Cyph, Inc. <[email protected]> (https://github.com/cyph)", | ||
"license": "BSD-2-Clause", | ||
"bugs": { | ||
"url": "https://github.com/cyph/sodiumutil/issues" | ||
} | ||
} |
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,57 @@ | ||
return { | ||
from_base64: function (data) { | ||
return typeof data === 'string' ? | ||
from_base64(data) : | ||
data | ||
; | ||
}, | ||
from_hex: function (data) { | ||
return typeof data === 'string' ? | ||
from_hex(data) : | ||
data | ||
; | ||
}, | ||
from_string: function (message) { | ||
return typeof message === 'string' ? | ||
from_string(message) : | ||
message | ||
; | ||
}, | ||
memcmp: memcmp, | ||
memzero: function (data) { | ||
if (data instanceof Uint8Array) { | ||
memzero(data); | ||
} | ||
else if (typeof Buffer !== 'undefined' && data instanceof Buffer) { | ||
data.fill(0); | ||
} | ||
}, | ||
to_base64: function (data) { | ||
return typeof data === 'string' ? | ||
data : | ||
to_base64(data).replace(/\s+/g, '') | ||
; | ||
}, | ||
to_hex: function (data) { | ||
return typeof data === 'string' ? | ||
data : | ||
to_hex(data).replace(/\s+/g, '') | ||
; | ||
}, | ||
to_string: function (message) { | ||
return typeof message === 'string' ? | ||
message : | ||
to_string(message) | ||
; | ||
} | ||
}; | ||
}()); | ||
|
||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
sodiumUtil.sodiumUtil = sodiumUtil; | ||
module.exports = sodiumUtil; | ||
} | ||
else { | ||
self.sodiumUtil = sodiumUtil; | ||
} |
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 @@ | ||
var sodiumUtil = (function () { |
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,29 @@ | ||
declare module 'sodiumutil' { | ||
interface ISodiumUtil { | ||
/** Converts base64 string into binary byte array. */ | ||
from_base64 (s: string) : Uint8Array; | ||
|
||
/** Converts hex string into binary byte array. */ | ||
from_hex (s: string) : Uint8Array; | ||
|
||
/** Converts ASCII/Unicode string into binary byte array. */ | ||
from_string (s: string) : Uint8Array; | ||
|
||
/** Indicates whether two blocks of memory contain the same data. */ | ||
memcmp (a: Uint8Array, b: Uint8Array) : boolean; | ||
|
||
/** Zeroes out memory. */ | ||
memzero (a: Uint8Array) : void; | ||
|
||
/** Converts binary into base64 string. */ | ||
to_base64 (a: Uint8Array) : string; | ||
|
||
/** Converts binary into hex string. */ | ||
to_hex (a: Uint8Array) : string; | ||
|
||
/** Converts binary into ASCII/Unicode string. */ | ||
to_string (a: Uint8Array) : string; | ||
} | ||
|
||
const sodiumUtil: ISodiumUtil; | ||
} |