/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
void Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv) { // Throw if the wrong type of ArrayBufferView is passed in // (Part of the Web Crypto API spec) switch (aArray.Type()) { case js::Scalar::Int8: case js::Scalar::Uint8: case js::Scalar::Uint8Clamped: case js::Scalar::Int16: case js::Scalar::Uint16: case js::Scalar::Int32: case js::Scalar::Uint32: case js::Scalar::BigInt64: case js::Scalar::BigUint64: break; default:
aRv.Throw(NS_ERROR_DOM_TYPE_MISMATCH_ERR); return;
}
nsCOMPtr<nsIRandomGenerator> randomGenerator =
do_GetService("@mozilla.org/security/random-generator;1"); if (!randomGenerator) {
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR); return;
}
aArray.ProcessFixedData([&](const Span<uint8_t>& aData) { if (aData.Length() == 0) {
NS_WARNING("ArrayBufferView length is 0, cannot continue");
aRetval.set(aArray.Obj()); return;
}
if (aData.Length() > 65536) {
aRv.ThrowQuotaExceededError( "getRandomValues can only generate maximum 65536 bytes"); return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.