OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
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 "modules/crypto/Algorithm.h" | 32 #include "modules/crypto/KeyAlgorithm.h" |
33 | 33 |
34 #include "modules/crypto/AesKeyAlgorithm.h" | |
35 #include "modules/crypto/HmacKeyAlgorithm.h" | |
34 #include "modules/crypto/NormalizeAlgorithm.h" | 36 #include "modules/crypto/NormalizeAlgorithm.h" |
37 #include "modules/crypto/RsaHashedKeyAlgorithm.h" | |
38 #include "modules/crypto/RsaKeyAlgorithm.h" | |
35 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
36 | 40 |
37 namespace WebCore { | 41 namespace WebCore { |
38 | 42 |
39 DEFINE_GC_INFO(Algorithm); | 43 DEFINE_GC_INFO(KeyAlgorithm); |
40 | 44 |
41 PassRefPtrWillBeRawPtr<Algorithm> Algorithm::create(const blink::WebCryptoAlgori thm& algorithm) | 45 PassRefPtrWillBeRawPtr<KeyAlgorithm> KeyAlgorithm::create(const blink::WebCrypto KeyAlgorithm& algorithm) |
42 { | 46 { |
43 return adoptRefWillBeNoop(new Algorithm(algorithm)); | 47 switch (algorithm.paramsType()) { |
48 case blink::WebCryptoKeyAlgorithmParamsTypeNone: | |
49 return adoptRefWillBeNoop(new KeyAlgorithm(algorithm)); | |
50 case blink::WebCryptoKeyAlgorithmParamsTypeAes: | |
51 return AesKeyAlgorithm::create(algorithm); | |
52 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | |
53 return HmacKeyAlgorithm::create(algorithm); | |
54 case blink::WebCryptoKeyAlgorithmParamsTypeRsa: | |
55 return RsaKeyAlgorithm::create(algorithm); | |
56 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: | |
57 return RsaHashedKeyAlgorithm::create(algorithm); | |
58 } | |
44 } | 59 } |
45 | 60 |
46 Algorithm::Algorithm(const blink::WebCryptoAlgorithm& algorithm) | 61 PassRefPtrWillBeRawPtr<KeyAlgorithm> KeyAlgorithm::createHash(const blink::WebCr yptoAlgorithm& hash) |
62 { | |
63 // Assume that none of the hash algorithms have any parameters. | |
64 ASSERT(hash.paramsType() == blink::WebCryptoAlgorithmParamsTypeNone); | |
65 return adoptRefWillBeNoop(new KeyAlgorithm(blink::WebCryptoKeyAlgorithm(hash .id(), nullptr))); | |
66 } | |
67 | |
68 KeyAlgorithm::KeyAlgorithm(const blink::WebCryptoKeyAlgorithm& algorithm) | |
47 : m_algorithm(algorithm) | 69 : m_algorithm(algorithm) |
48 { | 70 { |
49 ScriptWrappable::init(this); | 71 ScriptWrappable::init(this); |
50 } | 72 } |
51 | 73 |
52 String Algorithm::name() | 74 String KeyAlgorithm::name() |
53 { | 75 { |
54 return algorithmIdToName(m_algorithm.id()); | 76 return algorithmIdToName(m_algorithm.id()); |
55 } | 77 } |
56 | 78 |
79 blink::WebCryptoKeyAlgorithmParamsType KeyAlgorithm::type() const | |
80 { | |
81 return m_algorithm.paramsType(); | |
82 } | |
83 | |
84 void KeyAlgorithm::trace(Visitor*) { } | |
abarth-chromium
2014/02/25 07:51:41
The { and } should each be on separate lines.
eroman
2014/02/25 08:33:15
Moved to header
| |
85 | |
57 } // namespace WebCore | 86 } // namespace WebCore |
OLD | NEW |