/* -*- 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/. */
SRIMetadata::SRIMetadata(const nsACString& aToken)
: mAlgorithmType(SRIMetadata::UNKNOWN_ALGORITHM), mEmpty(false) {
MOZ_ASSERT(!aToken.IsEmpty()); // callers should check this first
bool SRIMetadata::operator<(const SRIMetadata& aOther) const {
static_assert(nsICryptoHash::SHA256 < nsICryptoHash::SHA384, "We rely on the order indicating relative alg strength");
static_assert(nsICryptoHash::SHA384 < nsICryptoHash::SHA512, "We rely on the order indicating relative alg strength");
MOZ_ASSERT(mAlgorithmType == SRIMetadata::UNKNOWN_ALGORITHM ||
mAlgorithmType == nsICryptoHash::SHA256 ||
mAlgorithmType == nsICryptoHash::SHA384 ||
mAlgorithmType == nsICryptoHash::SHA512);
MOZ_ASSERT(aOther.mAlgorithmType == SRIMetadata::UNKNOWN_ALGORITHM ||
aOther.mAlgorithmType == nsICryptoHash::SHA256 ||
aOther.mAlgorithmType == nsICryptoHash::SHA384 ||
aOther.mAlgorithmType == nsICryptoHash::SHA512);
if (mEmpty) {
SRIMETADATALOG(("SRIMetadata::operator<, first metadata is empty")); returntrue; // anything beats the empty metadata (incl. invalid ones)
}
// We only pull in the first element of the other metadata
MOZ_ASSERT(aOther.mHashes.Length() == 1); if (mHashes.Length() < SRIMetadata::MAX_ALTERNATE_HASHES) {
SRIMETADATALOG(( "SRIMetadata::operator+=, appending another '%s' hash (new length=%zu)",
mAlgorithm.get(), mHashes.Length()));
mHashes.AppendElement(aOther.mHashes[0]);
}
void SRIMetadata::GetHashType(int8_t* outType, uint32_t* outLength) const { // these constants are defined in security/nss/lib/util/hasht.h and // netwerk/base/public/nsICryptoHash.idl switch (mAlgorithmType) { case nsICryptoHash::SHA256:
*outLength = SHA256_LENGTH; break; case nsICryptoHash::SHA384:
*outLength = SHA384_LENGTH; break; case nsICryptoHash::SHA512:
*outLength = SHA512_LENGTH; break; default:
*outLength = 0;
}
*outType = mAlgorithmType;
}
bool SRIMetadata::CanTrustBeDelegatedTo(const SRIMetadata& aOther) const { if (IsEmpty()) { // No integrity requirements enforced, just let go. returntrue;
}
if (aOther.IsEmpty()) { // This metadata requires a check and the other has none, can't delegate. returnfalse;
}
if (mAlgorithmType != aOther.mAlgorithmType) { // They must use the same hash algorithm. returnfalse;
}
// They must be completely identical, except for the order of hashes. // We don't know which hash is the one passing eventually the check, so only // option is to require this metadata to contain the same set of hashes as the // one we want to delegate the trust to. if (mHashes.Length() != aOther.mHashes.Length()) { returnfalse;
}
for (constauto& hash : mHashes) { if (!aOther.mHashes.Contains(hash)) { returnfalse;
}
}
returntrue;
}
} // namespace mozilla::dom
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet)
¤
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.