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

Side by Side Diff: Source/modules/crypto/Key.cpp

Issue 295423004: Expose WebCrypto's algorithm normalization. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed comments. 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 blink::WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString) 89 blink::WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString)
90 { 90 {
91 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { 91 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) {
92 if (keyUsageMappings[i].name == usageString) 92 if (keyUsageMappings[i].name == usageString)
93 return keyUsageMappings[i].value; 93 return keyUsageMappings[i].value;
94 } 94 }
95 return 0; 95 return 0;
96 } 96 }
97 97
98 blink::WebCryptoKeyUsageMask toKeyUsage(AlgorithmOperation operation) 98 blink::WebCryptoKeyUsageMask toKeyUsage(blink::WebCryptoOperation operation)
99 { 99 {
100 switch (operation) { 100 switch (operation) {
101 case Encrypt: 101 case blink::WebCryptoOperationEncrypt:
102 return blink::WebCryptoKeyUsageEncrypt; 102 return blink::WebCryptoKeyUsageEncrypt;
103 case Decrypt: 103 case blink::WebCryptoOperationDecrypt:
104 return blink::WebCryptoKeyUsageDecrypt; 104 return blink::WebCryptoKeyUsageDecrypt;
105 case Sign: 105 case blink::WebCryptoOperationSign:
106 return blink::WebCryptoKeyUsageSign; 106 return blink::WebCryptoKeyUsageSign;
107 case Verify: 107 case blink::WebCryptoOperationVerify:
108 return blink::WebCryptoKeyUsageVerify; 108 return blink::WebCryptoKeyUsageVerify;
109 case DeriveKey: 109 case blink::WebCryptoOperationDeriveKey:
110 return blink::WebCryptoKeyUsageDeriveKey; 110 return blink::WebCryptoKeyUsageDeriveKey;
111 case DeriveBits: 111 case blink::WebCryptoOperationDeriveBits:
112 return blink::WebCryptoKeyUsageDeriveBits; 112 return blink::WebCryptoKeyUsageDeriveBits;
113 case WrapKey: 113 case blink::WebCryptoOperationWrapKey:
114 return blink::WebCryptoKeyUsageWrapKey; 114 return blink::WebCryptoKeyUsageWrapKey;
115 case UnwrapKey: 115 case blink::WebCryptoOperationUnwrapKey:
116 return blink::WebCryptoKeyUsageUnwrapKey; 116 return blink::WebCryptoKeyUsageUnwrapKey;
117 case Digest: 117 case blink::WebCryptoOperationDigest:
118 case GenerateKey: 118 case blink::WebCryptoOperationGenerateKey:
119 case ImportKey: 119 case blink::WebCryptoOperationImportKey:
120 break; 120 break;
121 } 121 }
122 122
123 ASSERT_NOT_REACHED(); 123 ASSERT_NOT_REACHED();
124 return 0; 124 return 0;
125 } 125 }
126 126
127 } // namespace 127 } // namespace
128 128
129 Key::~Key() 129 Key::~Key()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 { 161 {
162 Vector<String> result; 162 Vector<String> result;
163 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) { 163 for (size_t i = 0; i < WTF_ARRAY_LENGTH(keyUsageMappings); ++i) {
164 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; 164 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value;
165 if (m_key.usages() & usage) 165 if (m_key.usages() & usage)
166 result.append(keyUsageToString(usage)); 166 result.append(keyUsageToString(usage));
167 } 167 }
168 return result; 168 return result;
169 } 169 }
170 170
171 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, Algo rithmOperation op, CryptoResult* result) const 171 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, blin k::WebCryptoOperation op, CryptoResult* result) const
172 { 172 {
173 if (!(m_key.usages() & toKeyUsage(op))) { 173 if (!(m_key.usages() & toKeyUsage(op))) {
174 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key.u sages does not permit this operation"); 174 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key.u sages does not permit this operation");
175 return false; 175 return false;
176 } 176 }
177 177
178 if (m_key.algorithm().id() != algorithm.id()) { 178 if (m_key.algorithm().id() != algorithm.id()) {
179 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key.a lgorithm does not match that of operation"); 179 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key.a lgorithm does not match that of operation");
180 return false; 180 return false;
181 } 181 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 220 }
221 return true; 221 return true;
222 } 222 }
223 223
224 void Key::trace(Visitor* visitor) 224 void Key::trace(Visitor* visitor)
225 { 225 {
226 visitor->trace(m_algorithm); 226 visitor->trace(m_algorithm);
227 } 227 }
228 228
229 } // namespace WebCore 229 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698