1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SubresourceIntegrity_h
6 #define SubresourceIntegrity_h
8 #include "core/CoreExport.h"
9 #include "platform/Crypto.h"
10 #include "wtf/Allocator.h"
23 class CORE_EXPORT SubresourceIntegrity
{
24 STATIC_ONLY(SubresourceIntegrity
);
26 enum IntegrityParseResult
{
27 IntegrityParseValidResult
,
28 IntegrityParseNoValidResult
31 static bool CheckSubresourceIntegrity(const Element
&, const WTF::String
& content
, const KURL
& resourceUrl
, const Resource
&);
32 static bool CheckSubresourceIntegrity(const String
&, const WTF::String
& content
, const KURL
& resourceUrl
, Document
&, WTF::String
&);
35 // FIXME: After the merge with the Chromium repo, this should be refactored
36 // to use FRIEND_TEST in base/gtest_prod_util.h.
37 friend class SubresourceIntegrityTest
;
38 friend class SubresourceIntegrityTest_Parsing_Test
;
39 friend class SubresourceIntegrityTest_ParseAlgorithm_Test
;
40 friend class SubresourceIntegrityTest_Prioritization_Test
;
42 enum AlgorithmParseResult
{
48 struct IntegrityMetadata
{
50 HashAlgorithm algorithm
;
53 static HashAlgorithm
getPrioritizedHashFunction(HashAlgorithm
, HashAlgorithm
);
54 static AlgorithmParseResult
parseAlgorithm(const UChar
*& begin
, const UChar
* end
, HashAlgorithm
&);
55 static bool parseDigest(const UChar
*& begin
, const UChar
* end
, String
& digest
);
57 static IntegrityParseResult
parseIntegrityAttribute(const WTF::String
& attribute
, WTF::Vector
<IntegrityMetadata
>& metadataList
, Document
&);