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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 WebKit::WebCryptoAlgorithm algorithm; | 70 WebKit::WebCryptoAlgorithm algorithm; |
71 if (!normalizeAlgorithm(rawAlgorithm, operationType, algorithm, es)) | 71 if (!normalizeAlgorithm(rawAlgorithm, operationType, algorithm, es)) |
72 return ScriptPromise(); | 72 return ScriptPromise(); |
73 | 73 |
74 if (requiresKey && !key->canBeUsedForAlgorithm(algorithm, operationType, es)
) | 74 if (requiresKey && !key->canBeUsedForAlgorithm(algorithm, operationType, es)
) |
75 return ScriptPromise(); | 75 return ScriptPromise(); |
76 | 76 |
77 const unsigned char* data = static_cast<const unsigned char*>(dataBuffer->ba
seAddress()); | 77 const unsigned char* data = static_cast<const unsigned char*>(dataBuffer->ba
seAddress()); |
78 unsigned dataSize = dataBuffer->byteLength(); | 78 unsigned dataSize = dataBuffer->byteLength(); |
79 | 79 |
80 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); | 80 ScriptPromise promise = ScriptPromise::createPending(); |
| 81 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
81 | 82 |
82 switch (operationType) { | 83 switch (operationType) { |
83 case Encrypt: | 84 case Encrypt: |
84 WebKit::Platform::current()->crypto()->encrypt(algorithm, key->key(), da
ta, dataSize, result->result()); | 85 WebKit::Platform::current()->crypto()->encrypt(algorithm, key->key(), da
ta, dataSize, result->result()); |
85 break; | 86 break; |
86 case Decrypt: | 87 case Decrypt: |
87 WebKit::Platform::current()->crypto()->decrypt(algorithm, key->key(), da
ta, dataSize, result->result()); | 88 WebKit::Platform::current()->crypto()->decrypt(algorithm, key->key(), da
ta, dataSize, result->result()); |
88 break; | 89 break; |
89 case Sign: | 90 case Sign: |
90 WebKit::Platform::current()->crypto()->sign(algorithm, key->key(), data,
dataSize, result->result()); | 91 WebKit::Platform::current()->crypto()->sign(algorithm, key->key(), data,
dataSize, result->result()); |
91 break; | 92 break; |
92 case Verify: | 93 case Verify: |
93 WebKit::Platform::current()->crypto()->verifySignature(algorithm, key->k
ey(), reinterpret_cast<const unsigned char*>(signature->baseAddress()), signatur
e->byteLength(), data, dataSize, result->result()); | 94 WebKit::Platform::current()->crypto()->verifySignature(algorithm, key->k
ey(), reinterpret_cast<const unsigned char*>(signature->baseAddress()), signatur
e->byteLength(), data, dataSize, result->result()); |
94 break; | 95 break; |
95 case Digest: | 96 case Digest: |
96 WebKit::Platform::current()->crypto()->digest(algorithm, data, dataSize,
result->result()); | 97 WebKit::Platform::current()->crypto()->digest(algorithm, data, dataSize,
result->result()); |
97 break; | 98 break; |
98 default: | 99 default: |
99 ASSERT_NOT_REACHED(); | 100 ASSERT_NOT_REACHED(); |
100 return ScriptPromise(); | 101 return ScriptPromise(); |
101 } | 102 } |
102 | 103 |
103 return result->promise(); | 104 return promise; |
104 } | 105 } |
105 | 106 |
106 } // namespace | 107 } // namespace |
107 | 108 |
108 SubtleCrypto::SubtleCrypto() | 109 SubtleCrypto::SubtleCrypto() |
109 { | 110 { |
110 ScriptWrappable::init(this); | 111 ScriptWrappable::init(this); |
111 } | 112 } |
112 | 113 |
113 ScriptPromise SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, Ar
rayBufferView* data, ExceptionState& es) | 114 ScriptPromise SubtleCrypto::encrypt(const Dictionary& rawAlgorithm, Key* key, Ar
rayBufferView* data, ExceptionState& es) |
(...skipping 24 matching lines...) Expand all Loading... |
138 ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool ext
ractable, const Vector<String>& rawKeyUsages, ExceptionState& es) | 139 ScriptPromise SubtleCrypto::generateKey(const Dictionary& rawAlgorithm, bool ext
ractable, const Vector<String>& rawKeyUsages, ExceptionState& es) |
139 { | 140 { |
140 WebKit::WebCryptoKeyUsageMask keyUsages; | 141 WebKit::WebCryptoKeyUsageMask keyUsages; |
141 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, es)) | 142 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, es)) |
142 return ScriptPromise(); | 143 return ScriptPromise(); |
143 | 144 |
144 WebKit::WebCryptoAlgorithm algorithm; | 145 WebKit::WebCryptoAlgorithm algorithm; |
145 if (!normalizeAlgorithm(rawAlgorithm, GenerateKey, algorithm, es)) | 146 if (!normalizeAlgorithm(rawAlgorithm, GenerateKey, algorithm, es)) |
146 return ScriptPromise(); | 147 return ScriptPromise(); |
147 | 148 |
148 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); | 149 ScriptPromise promise = ScriptPromise::createPending(); |
| 150 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
149 WebKit::Platform::current()->crypto()->generateKey(algorithm, extractable, k
eyUsages, result->result()); | 151 WebKit::Platform::current()->crypto()->generateKey(algorithm, extractable, k
eyUsages, result->result()); |
150 return result->promise(); | 152 return promise; |
151 } | 153 } |
152 | 154 |
153 ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView*
keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>&
rawKeyUsages, ExceptionState& es) | 155 ScriptPromise SubtleCrypto::importKey(const String& rawFormat, ArrayBufferView*
keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>&
rawKeyUsages, ExceptionState& es) |
154 { | 156 { |
155 WebKit::WebCryptoKeyFormat format; | 157 WebKit::WebCryptoKeyFormat format; |
156 if (!Key::parseFormat(rawFormat, format, es)) | 158 if (!Key::parseFormat(rawFormat, format, es)) |
157 return ScriptPromise(); | 159 return ScriptPromise(); |
158 | 160 |
159 if (!keyData) { | 161 if (!keyData) { |
160 es.throwTypeError("Invalid keyData argument"); | 162 es.throwTypeError("Invalid keyData argument"); |
161 return ScriptPromise(); | 163 return ScriptPromise(); |
162 } | 164 } |
163 | 165 |
164 WebKit::WebCryptoKeyUsageMask keyUsages; | 166 WebKit::WebCryptoKeyUsageMask keyUsages; |
165 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, es)) | 167 if (!Key::parseUsageMask(rawKeyUsages, keyUsages, es)) |
166 return ScriptPromise(); | 168 return ScriptPromise(); |
167 | 169 |
168 WebKit::WebCryptoAlgorithm algorithm; | 170 WebKit::WebCryptoAlgorithm algorithm; |
169 if (!normalizeAlgorithm(rawAlgorithm, ImportKey, algorithm, es)) | 171 if (!normalizeAlgorithm(rawAlgorithm, ImportKey, algorithm, es)) |
170 return ScriptPromise(); | 172 return ScriptPromise(); |
171 | 173 |
172 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); | 174 const unsigned char* keyDataBytes = static_cast<unsigned char*>(keyData->bas
eAddress()); |
173 | 175 |
174 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); | 176 ScriptPromise promise = ScriptPromise::createPending(); |
| 177 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
175 WebKit::Platform::current()->crypto()->importKey(format, keyDataBytes, keyDa
ta->byteLength(), algorithm, extractable, keyUsages, result->result()); | 178 WebKit::Platform::current()->crypto()->importKey(format, keyDataBytes, keyDa
ta->byteLength(), algorithm, extractable, keyUsages, result->result()); |
176 return result->promise(); | 179 return promise; |
177 } | 180 } |
178 | 181 |
179 ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key, Excepti
onState& es) | 182 ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key, Excepti
onState& es) |
180 { | 183 { |
181 WebKit::WebCryptoKeyFormat format; | 184 WebKit::WebCryptoKeyFormat format; |
182 if (!Key::parseFormat(rawFormat, format, es)) | 185 if (!Key::parseFormat(rawFormat, format, es)) |
183 return ScriptPromise(); | 186 return ScriptPromise(); |
184 | 187 |
185 if (!key) { | 188 if (!key) { |
186 es.throwTypeError("Invalid key argument"); | 189 es.throwTypeError("Invalid key argument"); |
187 return ScriptPromise(); | 190 return ScriptPromise(); |
188 } | 191 } |
189 | 192 |
190 if (!key->extractable()) { | 193 if (!key->extractable()) { |
191 es.throwDOMException(NotSupportedError, "key is not extractable"); | 194 es.throwDOMException(NotSupportedError, "key is not extractable"); |
192 return ScriptPromise(); | 195 return ScriptPromise(); |
193 } | 196 } |
194 | 197 |
195 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(); | 198 ScriptPromise promise = ScriptPromise::createPending(); |
| 199 RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise); |
196 WebKit::Platform::current()->crypto()->exportKey(format, key->key(), result-
>result()); | 200 WebKit::Platform::current()->crypto()->exportKey(format, key->key(), result-
>result()); |
197 return result->promise(); | 201 return promise; |
198 } | 202 } |
199 | 203 |
200 } // namespace WebCore | 204 } // namespace WebCore |
OLD | NEW |