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