Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 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 "modules/crypto/Key.h" | |
| 33 | |
| 34 #include "modules/crypto/Algorithm.h" | |
| 35 | |
| 36 namespace WebCore { | |
| 37 | |
| 38 namespace { | |
| 39 | |
| 40 const char* keyTypeToString(WebKit::WebCryptoKeyType type) | |
| 41 { | |
| 42 switch (type) { | |
| 43 case WebKit::WebCryptoKeyTypeSecret: | |
| 44 return "secret"; | |
| 45 case WebKit::WebCryptoKeyTypePublic: | |
| 46 return "public"; | |
| 47 case WebKit::WebCryptoKeyTypePrivate: | |
| 48 return "private"; | |
| 49 } | |
| 50 ASSERT_NOT_REACHED(); | |
| 51 return 0; | |
| 52 } | |
| 53 | |
| 54 const char* keyUsageToString(WebKit::WebCryptoKeyUsage usage) | |
| 55 { | |
| 56 switch (usage) { | |
| 57 case WebKit::WebCryptoKeyUsageEncrypt: | |
| 58 return "encrypt"; | |
| 59 case WebKit::WebCryptoKeyUsageDecrypt: | |
| 60 return "decrypt"; | |
| 61 case WebKit::WebCryptoKeyUsageSign: | |
| 62 return "sign"; | |
| 63 case WebKit::WebCryptoKeyUsageVerify: | |
| 64 return "verify"; | |
| 65 case WebKit::WebCryptoKeyUsageDerive: | |
| 66 return "derive"; | |
| 67 case WebKit::WebCryptoKeyUsageWrap: | |
| 68 return "wrap"; | |
| 69 case WebKit::WebCryptoKeyUsageUnwrap: | |
| 70 return "unwrap"; | |
| 71 } | |
| 72 return 0; | |
|
abarth-chromium
2013/07/03 18:01:41
ASSERT_NOT_REACHED();
eroman
2013/07/03 19:18:06
I am in fact relying on the 0 case here:
<long_wi
| |
| 73 } | |
| 74 | |
| 75 } // namespace | |
| 76 | |
| 77 Key::Key(const WebKit::WebCryptoKey& key) | |
| 78 : m_key(key) | |
| 79 { | |
| 80 ScriptWrappable::init(this); | |
| 81 } | |
| 82 | |
| 83 String Key::type() const | |
| 84 { | |
| 85 return ASCIILiteral(keyTypeToString(m_key.type())); | |
| 86 } | |
| 87 | |
| 88 bool Key::extractable() const | |
| 89 { | |
| 90 return m_key.extractable(); | |
| 91 } | |
| 92 | |
| 93 Algorithm* Key::algorithm() | |
| 94 { | |
| 95 if (!m_algorithm) | |
| 96 m_algorithm = Algorithm::create(m_key.algorithm()); | |
| 97 return m_algorithm.get(); | |
| 98 } | |
| 99 | |
| 100 Vector<String> Key::keyUsage() const | |
| 101 { | |
| 102 Vector<String> v; | |
|
abarth-chromium
2013/07/03 18:01:41
v -> result
Please use complete words in variable
eroman
2013/07/03 19:18:06
Done.
| |
| 103 | |
| 104 // The WebCryptoKeyUsage values are consecutive powers of 2. Test each one i n order. | |
| 105 for (int i = 0; ; ++i) { | |
| 106 // Note that this won't be a valid WebCryptoKeyUsage during the last ite ration. | |
| 107 WebKit::WebCryptoKeyUsage usage = static_cast<WebKit::WebCryptoKeyUsage> (1 << i); | |
| 108 const char* usageString = keyUsageToString(usage); | |
| 109 if (!usageString) | |
| 110 break; | |
| 111 | |
| 112 if (m_key.keyUsage() & usage) | |
| 113 v.append(ASCIILiteral(usageString)); | |
| 114 } | |
| 115 return v; | |
| 116 } | |
| 117 | |
| 118 } // namespace WebCore | |
| OLD | NEW |