/* static */ nsresult SRICheck::VerifyIntegrity(const SRIMetadata& aMetadata, nsIUnicharStreamLoader* aLoader, const CORSMode aCORSMode, const nsAString& aString, const nsIDocument* aDocument) { NS_ENSURE_ARG_POINTER(aLoader); NS_ConvertUTF16toUTF8 utf8Hash(aString); nsCOMPtr<nsIChannel> channel; aLoader->GetChannel(getter_AddRefs(channel)); if (MOZ_LOG_TEST(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug)) { nsAutoCString requestURL; nsCOMPtr<nsIURI> originalURI; if (channel && NS_SUCCEEDED(channel->GetOriginalURI(getter_AddRefs(originalURI))) && originalURI) { originalURI->GetAsciiSpec(requestURL); } SRILOG(("SRICheck::VerifyIntegrity (unichar stream)")); } SRICheckDataVerifier verifier(aMetadata, aDocument); nsresult rv; rv = verifier.Update(utf8Hash.Length(), (uint8_t*)utf8Hash.get()); NS_ENSURE_SUCCESS(rv, rv); return verifier.Verify(aMetadata, channel, aCORSMode, aDocument); }
/* The filenames within the zip file are added to a hash-table for faster access. To save memory, the entries point directly into the zip file's central directory. However, filenames within the directory are not null- terminated. This means the path length must be read each time. As the utf8 routines operate on null-terminated strings, the filename must also be copied into a temporary buffer. This is NOT performance critical, as the hash is calculated only once per entry (on insertion) */ int zipHash(char *path) { int path_len = READ_LE_SHORT((unsigned char*)path + (CEN_FILE_PATHLEN_OFFSET - CEN_FILE_HEADER_LEN)); char buff[path_len + 1]; memcpy(buff, path, path_len); buff[path_len] = '\0'; return utf8Hash(buff); }
/* static */ nsresult SRICheck::VerifyIntegrity(const SRIMetadata& aMetadata, nsIURI* aRequestURI, const CORSMode aCORSMode, const nsAString& aString, const nsIDocument* aDocument) { NS_ConvertUTF16toUTF8 utf8Hash(aString); return VerifyIntegrity(aMetadata, aRequestURI, aCORSMode, utf8Hash.Length(), (uint8_t*)utf8Hash.get(), aDocument); }