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 11 matching lines...) Expand all Loading... |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
| 32 #include "public/platform/WebCryptoKey.h" |
| 33 |
32 #include "public/platform/WebCryptoAlgorithm.h" | 34 #include "public/platform/WebCryptoAlgorithm.h" |
33 | |
34 #include "public/platform/WebCryptoAlgorithmParams.h" | |
35 #include "wtf/OwnPtr.h" | 35 #include "wtf/OwnPtr.h" |
36 #include "wtf/ThreadSafeRefCounted.h" | 36 #include "wtf/ThreadSafeRefCounted.h" |
37 | 37 |
38 namespace WebKit { | 38 namespace WebKit { |
39 | 39 |
40 class WebCryptoAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoAlgorithm
Private> { | 40 class WebCryptoKeyPrivate : public ThreadSafeRefCounted<WebCryptoKeyPrivate> { |
41 public: | 41 public: |
42 WebCryptoAlgorithmPrivate(WebCryptoAlgorithmId algorithmId, const char* algo
rithmName, PassOwnPtr<WebCryptoAlgorithmParams> params) | 42 WebCryptoKeyPrivate(PassOwnPtr<WebCryptoKeyHandle> handle, WebCryptoKeyType
type, bool extractable, const WebCryptoAlgorithm& algorithm, WebCryptoKeyUsageMa
sk keyUsage) |
43 : algorithmId(algorithmId) | 43 : handle(handle) |
44 , algorithmName(algorithmName) | 44 , type(type) |
45 , params(params) | 45 , extractable(extractable) |
| 46 , algorithm(algorithm) |
| 47 , keyUsage(keyUsage) |
46 { | 48 { |
47 } | 49 } |
48 | 50 |
49 WebCryptoAlgorithmId algorithmId; | 51 const OwnPtr<WebCryptoKeyHandle> handle; |
50 const char* const algorithmName; | 52 const WebCryptoKeyType type; |
51 OwnPtr<WebCryptoAlgorithmParams> params; | 53 const bool extractable; |
| 54 const WebCryptoAlgorithm algorithm; |
| 55 const WebCryptoKeyUsageMask keyUsage; |
52 }; | 56 }; |
53 | 57 |
54 WebCryptoAlgorithm::WebCryptoAlgorithm(WebCryptoAlgorithmId algorithmId, const c
har* algorithmName, PassOwnPtr<WebCryptoAlgorithmParams> params) | 58 WebCryptoKey WebCryptoKey::create(WebCryptoKeyHandle* handle, WebCryptoKeyType t
ype, bool extractable, const WebCryptoAlgorithm& algorithm, WebCryptoKeyUsageMas
k keyUsage) |
55 : m_private(adoptRef(new WebCryptoAlgorithmPrivate(algorithmId, algorithmNam
e, params))) | |
56 { | 59 { |
| 60 WebCryptoKey key; |
| 61 key.m_private = adoptRef(new WebCryptoKeyPrivate(adoptPtr(handle), type, ext
ractable, algorithm, keyUsage)); |
| 62 return key; |
57 } | 63 } |
58 | 64 |
59 WebCryptoAlgorithmId WebCryptoAlgorithm::algorithmId() const | 65 WebCryptoKeyHandle* WebCryptoKey::handle() const |
60 { | 66 { |
61 return m_private->algorithmId; | 67 return m_private->handle.get(); |
62 } | 68 } |
63 | 69 |
64 const char* WebCryptoAlgorithm::algorithmName() const | 70 WebCryptoKeyType WebCryptoKey::type() const |
65 { | 71 { |
66 return m_private->algorithmName; | 72 return m_private->type; |
67 } | 73 } |
68 | 74 |
69 WebCryptoAlgorithmParamsType WebCryptoAlgorithm::paramsType() const | 75 bool WebCryptoKey::extractable() const |
70 { | 76 { |
71 if (!m_private->params) | 77 return m_private->extractable; |
72 return WebCryptoAlgorithmParamsTypeNone; | |
73 return m_private->params->type(); | |
74 } | 78 } |
75 | 79 |
76 WebCryptoAesCbcParams* WebCryptoAlgorithm::aesCbcParams() const | 80 const WebCryptoAlgorithm& WebCryptoKey::algorithm() const |
77 { | 81 { |
78 if (paramsType() == WebCryptoAlgorithmParamsTypeAesCbcParams) | 82 return m_private->algorithm; |
79 return static_cast<WebCryptoAesCbcParams*>(m_private->params.get()); | |
80 return 0; | |
81 } | 83 } |
82 | 84 |
83 WebCryptoAesKeyGenParams* WebCryptoAlgorithm::aesKeyGenParams() const | 85 WebCryptoKeyUsageMask WebCryptoKey::keyUsage() const |
84 { | 86 { |
85 if (paramsType() == WebCryptoAlgorithmParamsTypeAesKeyGenParams) | 87 return m_private->keyUsage; |
86 return static_cast<WebCryptoAesKeyGenParams*>(m_private->params.get()); | |
87 return 0; | |
88 } | 88 } |
89 | 89 |
90 void WebCryptoAlgorithm::assign(const WebCryptoAlgorithm& other) | 90 void WebCryptoKey::assign(const WebCryptoKey& other) |
91 { | 91 { |
92 m_private = other.m_private; | 92 m_private = other.m_private; |
93 } | 93 } |
94 | 94 |
95 void WebCryptoAlgorithm::reset() | 95 void WebCryptoKey::reset() |
96 { | 96 { |
97 m_private.reset(); | 97 m_private.reset(); |
98 } | 98 } |
99 | 99 |
100 } // namespace WebKit | 100 } // namespace WebKit |
OLD | NEW |