OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #include "config.h" |
| 32 #include "public/platform/WebCryptoKeyAlgorithm.h" |
| 33 |
| 34 #include "wtf/OwnPtr.h" |
| 35 #include "wtf/ThreadSafeRefCounted.h" |
| 36 |
| 37 namespace blink { |
| 38 |
| 39 class WebCryptoKeyAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoKeyAlg
orithmPrivate> { |
| 40 public: |
| 41 WebCryptoKeyAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoKe
yAlgorithmParams> params) |
| 42 : id(id) |
| 43 , params(params) |
| 44 { |
| 45 } |
| 46 |
| 47 WebCryptoAlgorithmId id; |
| 48 OwnPtr<WebCryptoKeyAlgorithmParams> params; |
| 49 }; |
| 50 |
| 51 WebCryptoKeyAlgorithm::WebCryptoKeyAlgorithm(WebCryptoAlgorithmId id, PassOwnPtr
<WebCryptoKeyAlgorithmParams> params) |
| 52 : m_private(adoptRef(new WebCryptoKeyAlgorithmPrivate(id, params))) |
| 53 { |
| 54 } |
| 55 |
| 56 WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::adoptParamsAndCreate(WebCryptoAlgor
ithmId id, WebCryptoKeyAlgorithmParams* params) |
| 57 { |
| 58 return WebCryptoKeyAlgorithm(id, adoptPtr(params)); |
| 59 } |
| 60 |
| 61 bool WebCryptoKeyAlgorithm::isNull() const |
| 62 { |
| 63 return m_private.isNull(); |
| 64 } |
| 65 |
| 66 WebCryptoAlgorithmId WebCryptoKeyAlgorithm::id() const |
| 67 { |
| 68 ASSERT(!isNull()); |
| 69 return m_private->id; |
| 70 } |
| 71 |
| 72 WebCryptoKeyAlgorithmParamsType WebCryptoKeyAlgorithm::paramsType() const |
| 73 { |
| 74 ASSERT(!isNull()); |
| 75 if (!m_private->params.get()) |
| 76 return WebCryptoKeyAlgorithmParamsTypeNone; |
| 77 return m_private->params->type(); |
| 78 } |
| 79 |
| 80 WebCryptoAesKeyAlgorithmParams* WebCryptoKeyAlgorithm::aesParams() const |
| 81 { |
| 82 ASSERT(!isNull()); |
| 83 if (paramsType() == WebCryptoKeyAlgorithmParamsTypeAes) |
| 84 return static_cast<WebCryptoAesKeyAlgorithmParams*>(m_private->params.ge
t()); |
| 85 return 0; |
| 86 } |
| 87 |
| 88 WebCryptoHmacKeyAlgorithmParams* WebCryptoKeyAlgorithm::hmacParams() const |
| 89 { |
| 90 ASSERT(!isNull()); |
| 91 if (paramsType() == WebCryptoKeyAlgorithmParamsTypeHmac) |
| 92 return static_cast<WebCryptoHmacKeyAlgorithmParams*>(m_private->params.g
et()); |
| 93 return 0; |
| 94 } |
| 95 |
| 96 WebCryptoRsaKeyAlgorithmParams* WebCryptoKeyAlgorithm::rsaParams() const |
| 97 { |
| 98 ASSERT(!isNull()); |
| 99 if (paramsType() == WebCryptoKeyAlgorithmParamsTypeRsa || paramsType() == We
bCryptoKeyAlgorithmParamsTypeRsaHashed) |
| 100 return static_cast<WebCryptoRsaKeyAlgorithmParams*>(m_private->params.ge
t()); |
| 101 return 0; |
| 102 } |
| 103 |
| 104 WebCryptoRsaHashedKeyAlgorithmParams* WebCryptoKeyAlgorithm::rsaHashedParams() c
onst |
| 105 { |
| 106 ASSERT(!isNull()); |
| 107 if (paramsType() == WebCryptoKeyAlgorithmParamsTypeRsaHashed) |
| 108 return static_cast<WebCryptoRsaHashedKeyAlgorithmParams*>(m_private->par
ams.get()); |
| 109 return 0; |
| 110 } |
| 111 |
| 112 void WebCryptoKeyAlgorithm::assign(const WebCryptoKeyAlgorithm& other) |
| 113 { |
| 114 m_private = other.m_private; |
| 115 } |
| 116 |
| 117 void WebCryptoKeyAlgorithm::reset() |
| 118 { |
| 119 m_private.reset(); |
| 120 } |
| 121 |
| 122 } // namespace blink |
OLD | NEW |