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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* k
eyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>&
rawKeyUsages, ExceptionState& es) | 120 ScriptObject SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView* k
eyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>&
rawKeyUsages, ExceptionState& es) |
121 { | 121 { |
122 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); | 122 WebKit::WebCrypto* platformCrypto = WebKit::Platform::current()->crypto(); |
123 if (!platformCrypto) { | 123 if (!platformCrypto) { |
124 es.throwDOMException(NotSupportedError); | 124 es.throwDOMException(NotSupportedError); |
125 return ScriptObject(); | 125 return ScriptObject(); |
126 } | 126 } |
127 | 127 |
| 128 if (!keyData) { |
| 129 es.throwDOMException(TypeError); |
| 130 return ScriptObject(); |
| 131 } |
| 132 |
128 WebKit::WebCryptoKeyUsageMask keyUsages; | 133 WebKit::WebCryptoKeyUsageMask keyUsages; |
129 if (!Key::parseUsageMask(rawKeyUsages, keyUsages)) { | 134 if (!Key::parseUsageMask(rawKeyUsages, keyUsages)) { |
130 es.throwDOMException(TypeError); | 135 es.throwDOMException(TypeError); |
131 return ScriptObject(); | 136 return ScriptObject(); |
132 } | 137 } |
133 | 138 |
134 WebKit::WebCryptoKeyFormat format; | 139 WebKit::WebCryptoKeyFormat format; |
135 if (!Key::parseFormat(rawFormat, format)) { | 140 if (!Key::parseFormat(rawFormat, format)) { |
136 es.throwDOMException(TypeError); | 141 es.throwDOMException(TypeError); |
137 return ScriptObject(); | 142 return ScriptObject(); |
138 } | 143 } |
139 | 144 |
140 WebKit::WebCryptoAlgorithm algorithm; | 145 WebKit::WebCryptoAlgorithm algorithm; |
141 if (!normalizeAlgorithmForImportKey(rawAlgorithm, algorithm, es)) | 146 if (!normalizeAlgorithmForImportKey(rawAlgorithm, algorithm, es)) |
142 return ScriptObject(); | 147 return ScriptObject(); |
143 | 148 |
144 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); | 149 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); |
145 | 150 |
146 RefPtr<KeyOperation> keyOp = KeyOperation::create(); | 151 RefPtr<KeyOperation> keyOp = KeyOperation::create(); |
147 WebKit::WebCryptoKeyOperationResult result(keyOp.get()); | 152 WebKit::WebCryptoKeyOperationResult result(keyOp.get()); |
148 platformCrypto->importKey(format, keyDataBytes, keyData->byteLength(), algor
ithm, extractable, keyUsages, result); | 153 platformCrypto->importKey(format, keyDataBytes, keyData->byteLength(), algor
ithm, extractable, keyUsages, result); |
149 return keyOp->returnValue(es); | 154 return keyOp->returnValue(es); |
150 } | 155 } |
151 | 156 |
152 } // namespace WebCore | 157 } // namespace WebCore |
OLD | NEW |