OLD | NEW |
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); | 170 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
171 | 171 |
172 blink::WebCryptoKeyFormat format; | 172 blink::WebCryptoKeyFormat format; |
173 if (!Key::parseFormat(rawFormat, format, result.get())) | 173 if (!Key::parseFormat(rawFormat, format, result.get())) |
174 return promise; | 174 return promise; |
175 | 175 |
176 blink::WebCryptoKeyUsageMask keyUsages; | 176 blink::WebCryptoKeyUsageMask keyUsages; |
177 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) | 177 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) |
178 return promise; | 178 return promise; |
179 | 179 |
180 // The algorithm is optional. | |
181 blink::WebCryptoAlgorithm algorithm; | 180 blink::WebCryptoAlgorithm algorithm; |
182 if (!rawAlgorithm.isUndefinedOrNull() && !parseAlgorithm(rawAlgorithm, Impor
tKey, algorithm, exceptionState, result.get())) | 181 if (!parseAlgorithm(rawAlgorithm, ImportKey, algorithm, exceptionState, resu
lt.get())) |
183 return promise; | 182 return promise; |
184 | 183 |
185 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); | 184 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); |
186 | 185 |
187 blink::Platform::current()->crypto()->importKey(format, keyDataBytes, keyDat
a->byteLength(), algorithm, extractable, keyUsages, result->result()); | 186 blink::Platform::current()->crypto()->importKey(format, keyDataBytes, keyDat
a->byteLength(), algorithm, extractable, keyUsages, result->result()); |
188 return promise; | 187 return promise; |
189 } | 188 } |
190 | 189 |
191 ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key, Excepti
onState& exceptionState) | 190 ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key, Excepti
onState& exceptionState) |
192 { | 191 { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 return promise; | 265 return promise; |
267 | 266 |
268 blink::WebCryptoKeyUsageMask keyUsages; | 267 blink::WebCryptoKeyUsageMask keyUsages; |
269 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) | 268 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get())) |
270 return promise; | 269 return promise; |
271 | 270 |
272 blink::WebCryptoAlgorithm unwrapAlgorithm; | 271 blink::WebCryptoAlgorithm unwrapAlgorithm; |
273 if (!parseAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, exceptio
nState, result.get())) | 272 if (!parseAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, exceptio
nState, result.get())) |
274 return promise; | 273 return promise; |
275 | 274 |
276 // The unwrappedKeyAlgorithm is optional. | |
277 blink::WebCryptoAlgorithm unwrappedKeyAlgorithm; | 275 blink::WebCryptoAlgorithm unwrappedKeyAlgorithm; |
278 if (!rawUnwrappedKeyAlgorithm.isUndefinedOrNull() && !parseAlgorithm(rawUnwr
appedKeyAlgorithm, ImportKey, unwrappedKeyAlgorithm, exceptionState, result.get(
))) | 276 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorit
hm, exceptionState, result.get())) |
279 return promise; | 277 return promise; |
280 | 278 |
281 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result
.get())) | 279 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, result
.get())) |
282 return promise; | 280 return promise; |
283 | 281 |
284 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap
pedKey->baseAddress()); | 282 const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrap
pedKey->baseAddress()); |
285 unsigned wrappedKeyDataSize = wrappedKey->byteLength(); | 283 unsigned wrappedKeyDataSize = wrappedKey->byteLength(); |
286 | 284 |
287 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap
pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex
tractable, keyUsages, result->result()); | 285 blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrap
pedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, ex
tractable, keyUsages, result->result()); |
288 return promise; | 286 return promise; |
289 } | 287 } |
290 | 288 |
291 } // namespace WebCore | 289 } // namespace WebCore |
OLD | NEW |