2021-01-12 02:13:41 +09:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2021-02-05 03:48:32 +05:30
|
|
|
"use strict";
|
2020-07-19 19:49:44 +02:00
|
|
|
|
|
|
|
((window) => {
|
2020-09-16 22:22:43 +02:00
|
|
|
const core = window.Deno.core;
|
2021-06-05 22:56:59 +02:00
|
|
|
const webidl = window.__bootstrap.webidl;
|
2021-01-10 17:27:15 +01:00
|
|
|
|
2021-06-05 22:56:59 +02:00
|
|
|
class Crypto {
|
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
2021-01-10 17:27:15 +01:00
|
|
|
}
|
2021-06-05 22:56:59 +02:00
|
|
|
|
|
|
|
getRandomValues(arrayBufferView) {
|
|
|
|
webidl.assertBranded(this, Crypto);
|
|
|
|
const prefix = "Failed to execute 'getRandomValues' on 'Crypto'";
|
|
|
|
webidl.requiredArguments(arguments.length, 1, { prefix });
|
|
|
|
arrayBufferView = webidl.converters.ArrayBufferView(arrayBufferView, {
|
|
|
|
prefix,
|
|
|
|
context: "Argument 1",
|
|
|
|
});
|
|
|
|
if (
|
|
|
|
!(
|
|
|
|
arrayBufferView instanceof Int8Array ||
|
|
|
|
arrayBufferView instanceof Uint8Array ||
|
|
|
|
arrayBufferView instanceof Int16Array ||
|
|
|
|
arrayBufferView instanceof Uint16Array ||
|
|
|
|
arrayBufferView instanceof Int32Array ||
|
|
|
|
arrayBufferView instanceof Uint32Array ||
|
|
|
|
arrayBufferView instanceof Uint8ClampedArray
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
throw new DOMException(
|
|
|
|
"The provided ArrayBufferView is not an integer array type",
|
|
|
|
"TypeMismatchError",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const ui8 = new Uint8Array(
|
|
|
|
arrayBufferView.buffer,
|
|
|
|
arrayBufferView.byteOffset,
|
|
|
|
arrayBufferView.byteLength,
|
2021-01-10 17:27:15 +01:00
|
|
|
);
|
2021-06-05 22:56:59 +02:00
|
|
|
core.opSync("op_crypto_get_random_values", ui8);
|
|
|
|
return arrayBufferView;
|
|
|
|
}
|
|
|
|
|
|
|
|
randomUUID() {
|
|
|
|
webidl.assertBranded(this, Crypto);
|
|
|
|
return core.opSync("op_crypto_random_uuid");
|
2021-01-10 17:27:15 +01:00
|
|
|
}
|
|
|
|
|
2021-06-05 22:56:59 +02:00
|
|
|
get [Symbol.toStringTag]() {
|
|
|
|
return "Crypto";
|
|
|
|
}
|
|
|
|
|
|
|
|
[Symbol.for("Deno.customInspect")](inspect) {
|
|
|
|
return `${this.constructor.name} ${inspect({})}`;
|
|
|
|
}
|
2021-06-05 14:46:24 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 19:49:44 +02:00
|
|
|
window.__bootstrap.crypto = {
|
2021-06-05 22:56:59 +02:00
|
|
|
crypto: webidl.createBranded(Crypto),
|
|
|
|
Crypto,
|
2020-07-19 19:49:44 +02:00
|
|
|
};
|
|
|
|
})(this);
|