Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function randomValues(byteLength: number): Promise {
// Find the global scope for this runtime
const globalScope = locateWindow();
if (supportsWebCrypto(globalScope)) {
return webCryptoRandomValues(byteLength);
} else if (isMsWindow(globalScope)) {
return ie11RandomValues(byteLength);
}
return Promise.reject(
new Error(`Unable to locate a secure random source.`)
);
}
return this.key.then(key => locateWindow().crypto.subtle
.sign(SHA_256_HMAC_ALGO, key, this.toHash)
.then(data => new Uint8Array(data))
);
constructor(secret?: SourceData) {
if (secret) {
this.operation = getKeyPromise(secret).then(keyData => (
(locateWindow() as MsWindow).msCrypto.subtle
.sign(SHA_256_HMAC_ALGO, keyData)
));
this.operation.catch(() => {});
} else {
this.operation = Promise.resolve(
(locateWindow() as MsWindow).msCrypto.subtle
.digest('SHA-256')
);
}
}
return new Promise(resolve => {
const randomBytes = new Uint8Array(byteLength);
locateWindow().crypto.getRandomValues(randomBytes);
resolve(randomBytes);
});
}
constructor(secret?: SourceData) {
if (supportsWebCrypto(locateWindow())) {
this.hash = new WebCryptoSha256(secret);
} else if (isMsWindow(locateWindow())) {
this.hash = new Ie11Sha256(secret);
} else {
this.hash = new JsSha256(secret);
}
}
constructor(secret?: SourceData) {
if (supportsWebCrypto(locateWindow())) {
this.hash = new WebCryptoSha256(secret);
} else if (isMsWindow(locateWindow())) {
this.hash = new Ie11Sha256(secret);
} else {
this.hash = new JsSha256(secret);
}
}
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
import { locateWindow } from '@aws-sdk/util-locate-window'
import { webCryptoBackendFactory } from './backend-factory'
const {
getWebCryptoBackend,
configureFallback
} = webCryptoBackendFactory(locateWindow())
export { getWebCryptoBackend, configureFallback }
export {
getNonZeroByteBackend,
getZeroByteSubtle,
isFullSupportWebCryptoBackend,
WebCryptoBackend,
FullSupportWebCryptoBackend,
MixedSupportWebCryptoBackend
} from './backend-factory'
export { synchronousRandomValues } from './synchronous_random_values'