// Treats an array as a set, and generates an array of all non-empty // subsets (which are themselves arrays). // // The order of members of the "subsets" is not guaranteed. function allNonemptySubsetsOf(arr) { var results = []; var firstElement; var remainingElements;
// Is key a CryptoKey object with correct algorithm, extractable, and usages? // Is it a secret, private, or public kind of key? function assert_goodCryptoKey(key, algorithm, extractable, usages, kind) { if (typeof algorithm === "string") {
algorithm = { name: algorithm };
}
var correctUsages = [];
var registeredAlgorithmName;
registeredAlgorithmNames.forEach(function(name) { if (name.toUpperCase() === algorithm.name.toUpperCase()) {
registeredAlgorithmName = name;
}
});
assert_equals(key.constructor, CryptoKey, "Is a CryptoKey");
assert_equals(key.type, kind, "Is a " + kind + " key");
assert_equals(key.extractable, extractable, "Extractability is correct");
if (/^(?:Ed|X)(?:25519|448)$/.test(key.algorithm.name)) {
assert_false('namedCurve' in key.algorithm, "Does not have a namedCurve property");
}
// usages is expected to be provided for a key pair, but we are checking // only a single key. The publicKey and privateKey portions of a key pair // recognize only some of the usages appropriate for a key pair. if (key.type === "public") {
["encrypt", "verify", "wrapKey", "encapsulateBits", "encapsulateKey"].forEach(function(usage) { if (usages.includes(usage)) {
correctUsages.push(usage);
}
});
} elseif (key.type === "private") {
["decrypt", "sign", "unwrapKey", "deriveKey", "deriveBits", "decapsulateBits", "decapsulateKey"].forEach(function(usage) { if (usages.includes(usage)) {
correctUsages.push(usage);
}
});
} else {
correctUsages = usages;
}
assert_equals((typeof key.usages), "object", key.type + " key.usages is an object");
assert_not_equals(key.usages, null, key.type + " key.usages isn't null");
// The usages parameter could have repeats, but the usages // property of the result should not. var usageCount = 0;
key.usages.forEach(function(usage) {
usageCount += 1;
assert_in_array(usage, correctUsages, "Has " + usage + " usage");
});
assert_equals(key.usages.length, usageCount, "usages property is correct");
assert_equals(key[Symbol.toStringTag], 'CryptoKey', "has the expected Symbol.toStringTag");
}
// The algorithm parameter is an object with a name and other // properties. Given the name, generate all valid parameters. function allAlgorithmSpecifiersFor(algorithmName) { var results = [];
// RSA key generation is slow. Test a minimal set of parameters var hashes = ["SHA-1", "SHA-256"];
// EC key generation is a lot faster. Check all curves in the spec var curves = ["P-256", "P-384", "P-521"];
// Create every possible valid usages parameter, given legal // usages. Note that an empty usages parameter is not always valid. // // There is an optional parameter - mandatoryUsages. If provided, // it should be an array containing those usages of which one must be // included. function allValidUsages(validUsages, emptyIsValid, mandatoryUsages) { if (typeof mandatoryUsages === "undefined") {
mandatoryUsages = [];
}
var okaySubsets = [];
allNonemptySubsetsOf(validUsages).forEach(function(subset) { if (mandatoryUsages.length === 0) {
okaySubsets.push(subset);
} else { for (var i=0; i<mandatoryUsages.length; i++) { if (subset.includes(mandatoryUsages[i])) {
okaySubsets.push(subset); return;
}
}
}
});
if (emptyIsValid && validUsages.length !== 0) {
okaySubsets.push([]);
}
okaySubsets.push(validUsages.concat(mandatoryUsages).concat(validUsages)); // Repeated values are allowed return okaySubsets;
}
function unique(names) { return [...new Set(names)];
}
// Algorithm name specifiers are case-insensitive. Generate several // case variations of a given name. function allNameVariants(name, slowTest) { var upCaseName = name.toUpperCase(); var lowCaseName = name.toLowerCase(); var mixedCaseName = upCaseName.substring(0, 1) + lowCaseName.substring(1);
// for slow tests effectively cut the amount of work in third by only // returning one variation if (slowTest) return [mixedCaseName]; return unique([upCaseName, lowCaseName, mixedCaseName]);
}
// Builds a hex string representation for an array-like input. // "bytes" can be an Array of bytes, an ArrayBuffer, or any TypedArray. // The output looks like this: // ab034c99 function bytesToHexString(bytes)
{ if (!bytes) returnnull;
bytes = new Uint8Array(bytes); var hexBytes = [];
for (var i = 0; i < bytes.length; ++i) { var byteString = bytes[i].toString(16); if (byteString.length < 2)
byteString = "0" + byteString;
hexBytes.push(byteString);
}
return hexBytes.join("");
}
function hexStringToUint8Array(hexString)
{ if (hexString.length % 2 != 0) throw"Invalid hexString"; var arrayBuffer = new Uint8Array(hexString.length / 2);
for (var i = 0; i < hexString.length; i += 2) { var byteValue = parseInt(hexString.substr(i, 2), 16); if (byteValue == NaN) throw"Invalid hexString";
arrayBuffer[i/2] = byteValue;
}
return arrayBuffer;
}
// Compares two ArrayBuffer or ArrayBufferView objects. If bitCount is // omitted, the two values must be the same length and have the same contents // in every byte. If bitCount is included, only that leading number of bits // have to match. function equalBuffers(a, b, bitCount) { var remainder;
// Returns a copy of the sourceBuffer it is sent. function copyBuffer(sourceBuffer) { var source = new Uint8Array(sourceBuffer); var copy = new Uint8Array(sourceBuffer.byteLength)
for (var i=0; i<source.byteLength; i++) {
copy[i] = source[i];
}
return copy;
}
// Are two Jwk objects "the same"? That is, does the object returned include // matching values for each property that was expected? It's okay if the // returned object has extra methods; they aren't checked. function equalJwk(expected, got) { var fields = Object.keys(expected); var fieldName;
for(var i=0; i<fields.length; i++) {
fieldName = fields[i]; if (!(fieldName in got)) { returnfalse;
} if (objectToString(expected[fieldName]) !== objectToString(got[fieldName])) { returnfalse;
}
}
returntrue;
}
// Jwk format wants Base 64 without the typical padding at the end. function byteArrayToUnpaddedBase64(byteArray){ var binaryString = ""; for (var i=0; i<byteArray.byteLength; i++){
binaryString += String.fromCharCode(byteArray[i]);
} var base64String = btoa(binaryString);
return base64String.replace(/=/g, "");
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.27 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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 und die Messung sind noch experimentell.