Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: content/child/webcrypto/algorithm_dispatch.cc

Issue 778543004: Add sanity check to generateKey to make sure usages aren't empty (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/child/webcrypto/algorithm_dispatch.h" 5 #include "content/child/webcrypto/algorithm_dispatch.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/algorithm_implementation.h" 8 #include "content/child/webcrypto/algorithm_implementation.h"
9 #include "content/child/webcrypto/algorithm_registry.h" 9 #include "content/child/webcrypto/algorithm_registry.h"
10 #include "content/child/webcrypto/crypto_data.h" 10 #include "content/child/webcrypto/crypto_data.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, 105 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
106 bool extractable, 106 bool extractable,
107 blink::WebCryptoKeyUsageMask usages, 107 blink::WebCryptoKeyUsageMask usages,
108 GenerateKeyResult* result) { 108 GenerateKeyResult* result) {
109 const AlgorithmImplementation* impl = NULL; 109 const AlgorithmImplementation* impl = NULL;
110 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 110 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
111 if (status.IsError()) 111 if (status.IsError())
112 return status; 112 return status;
113 113
114 return impl->GenerateKey(algorithm, extractable, usages, result); 114 status = impl->GenerateKey(algorithm, extractable, usages, result);
115 if (status.IsSuccess()) {
eroman 2014/12/05 19:41:55 style: Can you write this in the opposite directio
nharper 2014/12/05 23:15:47 Done.
116 const blink::WebCryptoKey* key = nullptr;
eroman 2014/12/05 19:41:55 Does this compile on all platforms? Not sure that
nharper 2014/12/05 23:15:47 Codesearch shows nullptr used in thousands of plac
117 if (result->type() == GenerateKeyResult::TYPE_SECRET_KEY) {
118 key = &result->secret_key();
119 }
120 if (result->type() == GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR) {
121 key = &result->private_key();
122 }
123 if (key != nullptr) {
124 // This should only fail if an algorithm is implemented incorrectly and
125 // does not do its own check of the usages.
126 DCHECK(key->usages() != 0)
eroman 2014/12/05 20:52:45 also: DCHECK_NE(0, key->usages());
nharper 2014/12/05 23:15:47 Since I need to do other things when the DCHECK co
127 << "Key usages for generateKey() must not be empty";
eroman 2014/12/05 19:41:55 Great. Can you also return an ErrorUnexpected here
nharper 2014/12/05 23:15:47 Done.
128 }
129 }
130 return status;
115 } 131 }
116 132
117 Status ImportKey(blink::WebCryptoKeyFormat format, 133 Status ImportKey(blink::WebCryptoKeyFormat format,
118 const CryptoData& key_data, 134 const CryptoData& key_data,
119 const blink::WebCryptoAlgorithm& algorithm, 135 const blink::WebCryptoAlgorithm& algorithm,
120 bool extractable, 136 bool extractable,
121 blink::WebCryptoKeyUsageMask usages, 137 blink::WebCryptoKeyUsageMask usages,
122 blink::WebCryptoKey* key) { 138 blink::WebCryptoKey* key) {
123 const AlgorithmImplementation* impl = NULL; 139 const AlgorithmImplementation* impl = NULL;
124 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); 140 Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return false; 304 return false;
289 305
290 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages, 306 status = impl->DeserializeKeyForClone(algorithm, type, extractable, usages,
291 key_data, key); 307 key_data, key);
292 return status.IsSuccess(); 308 return status.IsSuccess();
293 } 309 }
294 310
295 } // namespace webcrypto 311 } // namespace webcrypto
296 312
297 } // namespace content 313 } // namespace content
OLDNEW
« content/child/webcrypto/algorithm_dispatch.h ('K') | « content/child/webcrypto/algorithm_dispatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698