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

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

Issue 294393009: [webcrypto] Order jwk_ops the same way as Key.usages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a comment 'splaining to keep it sorted Created 6 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/webcrypto_util.h" 5 #include "content/child/webcrypto/webcrypto_util.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/child/webcrypto/status.h" 10 #include "content/child/webcrypto/status.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 const base::StringPiece string_piece( 56 const base::StringPiece string_piece(
57 reinterpret_cast<const char*>(Uint8VectorStart(input)), input.size()); 57 reinterpret_cast<const char*>(Uint8VectorStart(input)), input.size());
58 return Base64EncodeUrlSafe(string_piece); 58 return Base64EncodeUrlSafe(string_piece);
59 } 59 }
60 60
61 struct JwkToWebCryptoUsage { 61 struct JwkToWebCryptoUsage {
62 const char* const jwk_key_op; 62 const char* const jwk_key_op;
63 const blink::WebCryptoKeyUsage webcrypto_usage; 63 const blink::WebCryptoKeyUsage webcrypto_usage;
64 }; 64 };
65 65
66 // Keep this ordered according to the definition
67 // order of WebCrypto's "recognized key usage
68 // values".
69 //
70 // This is not required for spec compliance,
71 // however it makes the ordering of key_ops match
72 // that of WebCrypto's Key.usages.
66 const JwkToWebCryptoUsage kJwkWebCryptoUsageMap[] = { 73 const JwkToWebCryptoUsage kJwkWebCryptoUsageMap[] = {
67 {"encrypt", blink::WebCryptoKeyUsageEncrypt}, 74 {"encrypt", blink::WebCryptoKeyUsageEncrypt},
68 {"decrypt", blink::WebCryptoKeyUsageDecrypt}, 75 {"decrypt", blink::WebCryptoKeyUsageDecrypt},
76 {"sign", blink::WebCryptoKeyUsageSign},
77 {"verify", blink::WebCryptoKeyUsageVerify},
69 {"deriveKey", blink::WebCryptoKeyUsageDeriveKey}, 78 {"deriveKey", blink::WebCryptoKeyUsageDeriveKey},
70 {"deriveBits", blink::WebCryptoKeyUsageDeriveBits}, 79 {"deriveBits", blink::WebCryptoKeyUsageDeriveBits},
71 {"sign", blink::WebCryptoKeyUsageSign}, 80 {"wrapKey", blink::WebCryptoKeyUsageWrapKey},
72 {"unwrapKey", blink::WebCryptoKeyUsageUnwrapKey}, 81 {"unwrapKey", blink::WebCryptoKeyUsageUnwrapKey}};
73 {"verify", blink::WebCryptoKeyUsageVerify},
74 {"wrapKey", blink::WebCryptoKeyUsageWrapKey}};
75 82
76 // Modifies the input usage_mask by according to the key_op value. 83 // Modifies the input usage_mask by according to the key_op value.
77 bool JwkKeyOpToWebCryptoUsage(const std::string& key_op, 84 bool JwkKeyOpToWebCryptoUsage(const std::string& key_op,
78 blink::WebCryptoKeyUsageMask* usage_mask) { 85 blink::WebCryptoKeyUsageMask* usage_mask) {
79 for (size_t i = 0; i < arraysize(kJwkWebCryptoUsageMap); ++i) { 86 for (size_t i = 0; i < arraysize(kJwkWebCryptoUsageMap); ++i) {
80 if (kJwkWebCryptoUsageMap[i].jwk_key_op == key_op) { 87 if (kJwkWebCryptoUsageMap[i].jwk_key_op == key_op) {
81 *usage_mask |= kJwkWebCryptoUsageMap[i].webcrypto_usage; 88 *usage_mask |= kJwkWebCryptoUsageMap[i].webcrypto_usage;
82 return true; 89 return true;
83 } 90 }
84 } 91 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 198
192 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) { 199 bool IsAlgorithmAsymmetric(blink::WebCryptoAlgorithmId alg_id) {
193 // TODO(padolph): include all other asymmetric algorithms once they are 200 // TODO(padolph): include all other asymmetric algorithms once they are
194 // defined, e.g. EC and DH. 201 // defined, e.g. EC and DH.
195 return IsAlgorithmRsa(alg_id); 202 return IsAlgorithmRsa(alg_id);
196 } 203 }
197 204
198 } // namespace webcrypto 205 } // namespace webcrypto
199 206
200 } // namespace content 207 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698