102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch/* 202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * Copyright (C) 2013 Google Inc. All rights reserved. 302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * Redistribution and use in source and binary forms, with or without 502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * modification, are permitted provided that the following conditions are 602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * met: 702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * * Redistributions of source code must retain the above copyright 902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * notice, this list of conditions and the following disclaimer. 1002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * * Redistributions in binary form must reproduce the above 1102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * copyright notice, this list of conditions and the following disclaimer 1202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * in the documentation and/or other materials provided with the 1302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * distribution. 1402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * * Neither the name of Google Inc. nor the names of its 1502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * contributors may be used to endorse or promote products derived from 1602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * this software without specific prior written permission. 1702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 1802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch */ 3002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 3102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "config.h" 3202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "public/platform/WebCrypto.h" 33c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "platform/CryptoResult.h" 35c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#include "public/platform/WebArrayBuffer.h" 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/PassRefPtr.h" 37e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include <string.h> 3802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink { 4002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 41f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liuvoid WebCryptoResult::completeWithError(WebCryptoErrorType errorType, const WebString& errorDetails) 4202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 43f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu m_impl->completeWithError(errorType, errorDetails); 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) reset(); 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 47e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void WebCryptoResult::completeWithBuffer(const WebArrayBuffer& buffer) 4802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 49e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) RELEASE_ASSERT(!buffer.isNull()); 50e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) m_impl->completeWithBuffer(buffer); 5102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch reset(); 5202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 5302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 548abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)void WebCryptoResult::completeWithBuffer(const void* bytes, unsigned bytesSize) 55f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles){ 56e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) WebArrayBuffer buffer = WebArrayBuffer::create(bytesSize, 1); 57e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) RELEASE_ASSERT(!buffer.isNull()); 58e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) memcpy(buffer.data(), bytes, bytesSize); 59e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) completeWithBuffer(buffer); 6002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 6102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 625d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)void WebCryptoResult::completeWithJson(const char* utf8Data, unsigned length) 635d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles){ 645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) m_impl->completeWithJson(utf8Data, length); 655d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) reset(); 665d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)} 675d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) 68e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void WebCryptoResult::completeWithBoolean(bool b) 6902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 70e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) m_impl->completeWithBoolean(b); 7102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch reset(); 7202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 7302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 74e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void WebCryptoResult::completeWithKey(const WebCryptoKey& key) 7502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 7619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) ASSERT(!key.isNull()); 7702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch m_impl->completeWithKey(key); 7802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch reset(); 7902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 8002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 81c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)void WebCryptoResult::completeWithKeyPair(const WebCryptoKey& publicKey, const WebCryptoKey& privateKey) 82c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){ 8319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) ASSERT(!publicKey.isNull()); 8419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) ASSERT(!privateKey.isNull()); 85c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) m_impl->completeWithKeyPair(publicKey, privateKey); 86c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) reset(); 87c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)} 88c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 8976c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)bool WebCryptoResult::cancelled() const 9076c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles){ 9176c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) return m_impl->cancelled(); 9276c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles)} 9376c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) 94e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)WebCryptoResult::WebCryptoResult(const PassRefPtr<CryptoResult>& impl) 95c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) : m_impl(impl) 96c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles){ 97c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) ASSERT(m_impl.get()); 98c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)} 99c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 100e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void WebCryptoResult::reset() 10102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 10202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch m_impl.reset(); 10302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 10402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 105e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)void WebCryptoResult::assign(const WebCryptoResult& o) 10602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch{ 10702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch m_impl = o.m_impl; 10802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch} 10902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 11051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink 111