Skip to content

Commit

Permalink
Update dependencies; AWS-SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
dxdc committed Oct 3, 2023
1 parent a2dc87c commit 7afea8d
Show file tree
Hide file tree
Showing 6 changed files with 6,704 additions and 2,053 deletions.
2 changes: 1 addition & 1 deletion aws-sdk-js
Submodule aws-sdk-js updated 1282 files
4 changes: 2 additions & 2 deletions dist/AwsSdk.js

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions dist/Crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @module getRandomValuesPolyfill
*
* This module serves as a polyfill for the crypto.getRandomValues API. It's designed
* to provide a similar interface for generating cryptographically random values in
* environments where the native API is not available.
*
* Limitations:
* Not Cryptographically Secure: This implementation uses JavaScript's Math.random(),
* which is not suitable for cryptographic purposes.
*
* Attribution:
* This polyfill is based on the react-native-get-random-values package available at:
* https://github.com/LinusU/react-native-get-random-values
*
* @example
* const randomArray = new Uint8Array(10).fill(0);
* getRandomValues(randomArray);
*/

// Custom Error classes
class TypeMismatchError extends Error {}
class QuotaExceededError extends Error {}

function getInsecureRandomValues(array) {
for (let i = 0, r; i < array.length; i++) {
if ((i & 0x03) === 0) {
r = Math.random() * 0x100000000;
}
array[i] = (r >>> ((i & 0x03) << 3)) & 0xff;
}

return array;
}

/**
* @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Uint8ClampedArray} array
*/
function getRandomValues(array) {
if (
!(
array instanceof Int8Array ||
array instanceof Uint8Array ||
array instanceof Int16Array ||
array instanceof Uint16Array ||
array instanceof Int32Array ||
array instanceof Uint32Array ||
array instanceof Uint8ClampedArray
)
) {
throw new TypeMismatchError(`Expected an integer array, received ${typeof array}`);
}

if (array.byteLength > 65536) {
throw new QuotaExceededError('Can only request a maximum of 65536 bytes');
}

return getInsecureRandomValues(array);
}

var crypto = crypto || {};

if (typeof crypto.getRandomValues !== 'function') {
crypto.getRandomValues = getRandomValues;
}
Loading

0 comments on commit 7afea8d

Please sign in to comment.