OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/frame/SubresourceIntegrity.h" | 6 #include "core/frame/SubresourceIntegrity.h" |
7 | 7 |
8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/dom/Element.h" | 10 #include "core/dom/Element.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 { | 56 { |
57 static const struct { | 57 static const struct { |
58 HashAlgorithm algorithm; | 58 HashAlgorithm algorithm; |
59 const char* name; | 59 const char* name; |
60 } kAlgorithmToString[] = { | 60 } kAlgorithmToString[] = { |
61 { HashAlgorithmSha256, "SHA-256" }, | 61 { HashAlgorithmSha256, "SHA-256" }, |
62 { HashAlgorithmSha384, "SHA-384" }, | 62 { HashAlgorithmSha384, "SHA-384" }, |
63 { HashAlgorithmSha512, "SHA-512" } | 63 { HashAlgorithmSha512, "SHA-512" } |
64 }; | 64 }; |
65 | 65 |
66 // See comment in parseIntegrityAttribute about why sizeof() is used | 66 for (const auto& algorithmToString : kAlgorithmToString) { |
67 // instead of WTF_ARRAY_LENGTH. | 67 if (algorithmToString.algorithm == algorithm) |
68 size_t i = 0; | 68 return algorithmToString.name; |
69 size_t kSupportedAlgorithmsLength = sizeof(kAlgorithmToString) / sizeof(kAlg
orithmToString[0]); | |
70 for (; i < kSupportedAlgorithmsLength; i++) { | |
71 if (kAlgorithmToString[i].algorithm == algorithm) | |
72 return kAlgorithmToString[i].name; | |
73 } | 69 } |
74 | 70 |
75 ASSERT_NOT_REACHED(); | 71 ASSERT_NOT_REACHED(); |
76 return String(); | 72 return String(); |
77 } | 73 } |
78 | 74 |
79 static String digestToString(const DigestValue& digest) | 75 static String digestToString(const DigestValue& digest) |
80 { | 76 { |
81 return base64Encode(reinterpret_cast<const char*>(digest.data()), digest.siz
e(), Base64DoNotInsertLFs); | 77 return base64Encode(reinterpret_cast<const char*>(digest.data()), digest.siz
e(), Base64DoNotInsertLFs); |
82 } | 78 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute +
"'). The digest must be a valid, base64-encoded value.", document); | 232 logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute +
"'). The digest must be a valid, base64-encoded value.", document); |
237 return false; | 233 return false; |
238 } | 234 } |
239 | 235 |
240 // FIXME: Parse params in order to get content type (e.g. "?ct=application/j
avascript") | 236 // FIXME: Parse params in order to get content type (e.g. "?ct=application/j
avascript") |
241 | 237 |
242 return true; | 238 return true; |
243 } | 239 } |
244 | 240 |
245 } // namespace blink | 241 } // namespace blink |
OLD | NEW |