[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 5 | #include "components/webcrypto/algorithm_implementation.h" |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 6 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 7 | #include "components/webcrypto/status.h" |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 8 | |
| 9 | namespace webcrypto { |
| 10 | |
| 11 | AlgorithmImplementation::~AlgorithmImplementation() { |
| 12 | } |
| 13 | |
| 14 | Status AlgorithmImplementation::Encrypt( |
| 15 | const blink::WebCryptoAlgorithm& algorithm, |
| 16 | const blink::WebCryptoKey& key, |
| 17 | const CryptoData& data, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 18 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 19 | return Status::ErrorUnsupported(); |
| 20 | } |
| 21 | |
| 22 | Status AlgorithmImplementation::Decrypt( |
| 23 | const blink::WebCryptoAlgorithm& algorithm, |
| 24 | const blink::WebCryptoKey& key, |
| 25 | const CryptoData& data, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 26 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 27 | return Status::ErrorUnsupported(); |
| 28 | } |
| 29 | |
| 30 | Status AlgorithmImplementation::Sign(const blink::WebCryptoAlgorithm& algorithm, |
| 31 | const blink::WebCryptoKey& key, |
| 32 | const CryptoData& data, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 33 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 34 | return Status::ErrorUnsupported(); |
| 35 | } |
| 36 | |
| 37 | Status AlgorithmImplementation::Verify( |
| 38 | const blink::WebCryptoAlgorithm& algorithm, |
| 39 | const blink::WebCryptoKey& key, |
| 40 | const CryptoData& signature, |
| 41 | const CryptoData& data, |
| 42 | bool* signature_match) const { |
| 43 | return Status::ErrorUnsupported(); |
| 44 | } |
| 45 | |
| 46 | Status AlgorithmImplementation::Digest( |
| 47 | const blink::WebCryptoAlgorithm& algorithm, |
| 48 | const CryptoData& data, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 49 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 50 | return Status::ErrorUnsupported(); |
| 51 | } |
| 52 | |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 53 | Status AlgorithmImplementation::GenerateKey( |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 54 | const blink::WebCryptoAlgorithm& algorithm, |
| 55 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 56 | blink::WebCryptoKeyUsageMask usages, |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 57 | GenerateKeyResult* result) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 58 | return Status::ErrorUnsupported(); |
| 59 | } |
| 60 | |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 61 | Status AlgorithmImplementation::DeriveBits( |
| 62 | const blink::WebCryptoAlgorithm& algorithm, |
| 63 | const blink::WebCryptoKey& base_key, |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 64 | bool has_optional_length_bits, |
| 65 | unsigned int optional_length_bits, |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 66 | std::vector<uint8_t>* derived_bytes) const { |
| 67 | return Status::ErrorUnsupported(); |
| 68 | } |
| 69 | |
eroman | f93fd5b | 2014-12-11 00:21:06 | [diff] [blame] | 70 | Status AlgorithmImplementation::GetKeyLength( |
| 71 | const blink::WebCryptoAlgorithm& key_length_algorithm, |
| 72 | bool* has_length_bits, |
| 73 | unsigned int* length_bits) const { |
| 74 | return Status::ErrorUnsupported(); |
| 75 | } |
| 76 | |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 77 | Status AlgorithmImplementation::VerifyKeyUsagesBeforeImportKey( |
| 78 | blink::WebCryptoKeyFormat format, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 79 | blink::WebCryptoKeyUsageMask usages) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 80 | return Status::ErrorUnsupportedImportKeyFormat(); |
| 81 | } |
| 82 | |
eroman | a22536b2 | 2014-12-12 03:29:28 | [diff] [blame] | 83 | Status AlgorithmImplementation::ImportKey( |
| 84 | blink::WebCryptoKeyFormat format, |
| 85 | const CryptoData& key_data, |
| 86 | const blink::WebCryptoAlgorithm& algorithm, |
| 87 | bool extractable, |
| 88 | blink::WebCryptoKeyUsageMask usages, |
| 89 | blink::WebCryptoKey* key) const { |
| 90 | switch (format) { |
| 91 | case blink::WebCryptoKeyFormatRaw: |
| 92 | return ImportKeyRaw(key_data, algorithm, extractable, usages, key); |
| 93 | case blink::WebCryptoKeyFormatSpki: |
| 94 | return ImportKeySpki(key_data, algorithm, extractable, usages, key); |
| 95 | case blink::WebCryptoKeyFormatPkcs8: |
| 96 | return ImportKeyPkcs8(key_data, algorithm, extractable, usages, key); |
| 97 | case blink::WebCryptoKeyFormatJwk: |
| 98 | return ImportKeyJwk(key_data, algorithm, extractable, usages, key); |
| 99 | default: |
| 100 | return Status::ErrorUnsupported(); |
| 101 | } |
| 102 | } |
| 103 | |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 104 | Status AlgorithmImplementation::ImportKeyRaw( |
| 105 | const CryptoData& key_data, |
| 106 | const blink::WebCryptoAlgorithm& algorithm, |
| 107 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 108 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 109 | blink::WebCryptoKey* key) const { |
| 110 | return Status::ErrorUnsupportedImportKeyFormat(); |
| 111 | } |
| 112 | |
| 113 | Status AlgorithmImplementation::ImportKeyPkcs8( |
| 114 | const CryptoData& key_data, |
| 115 | const blink::WebCryptoAlgorithm& algorithm, |
| 116 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 117 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 118 | blink::WebCryptoKey* key) const { |
| 119 | return Status::ErrorUnsupportedImportKeyFormat(); |
| 120 | } |
| 121 | |
| 122 | Status AlgorithmImplementation::ImportKeySpki( |
| 123 | const CryptoData& key_data, |
| 124 | const blink::WebCryptoAlgorithm& algorithm, |
| 125 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 126 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 127 | blink::WebCryptoKey* key) const { |
| 128 | return Status::ErrorUnsupportedImportKeyFormat(); |
| 129 | } |
| 130 | |
| 131 | Status AlgorithmImplementation::ImportKeyJwk( |
| 132 | const CryptoData& key_data, |
| 133 | const blink::WebCryptoAlgorithm& algorithm, |
| 134 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 135 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 136 | blink::WebCryptoKey* key) const { |
| 137 | return Status::ErrorUnsupportedImportKeyFormat(); |
| 138 | } |
| 139 | |
eroman | a22536b2 | 2014-12-12 03:29:28 | [diff] [blame] | 140 | Status AlgorithmImplementation::ExportKey(blink::WebCryptoKeyFormat format, |
| 141 | const blink::WebCryptoKey& key, |
| 142 | std::vector<uint8_t>* buffer) const { |
| 143 | switch (format) { |
| 144 | case blink::WebCryptoKeyFormatRaw: |
| 145 | return ExportKeyRaw(key, buffer); |
| 146 | case blink::WebCryptoKeyFormatSpki: |
| 147 | return ExportKeySpki(key, buffer); |
| 148 | case blink::WebCryptoKeyFormatPkcs8: |
| 149 | return ExportKeyPkcs8(key, buffer); |
| 150 | case blink::WebCryptoKeyFormatJwk: |
| 151 | return ExportKeyJwk(key, buffer); |
| 152 | default: |
| 153 | return Status::ErrorUnsupported(); |
| 154 | } |
| 155 | } |
| 156 | |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 157 | Status AlgorithmImplementation::ExportKeyRaw( |
| 158 | const blink::WebCryptoKey& key, |
| 159 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 160 | return Status::ErrorUnsupportedExportKeyFormat(); |
| 161 | } |
| 162 | |
| 163 | Status AlgorithmImplementation::ExportKeyPkcs8( |
| 164 | const blink::WebCryptoKey& key, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 165 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 166 | return Status::ErrorUnsupportedExportKeyFormat(); |
| 167 | } |
| 168 | |
| 169 | Status AlgorithmImplementation::ExportKeySpki( |
| 170 | const blink::WebCryptoKey& key, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 171 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 172 | return Status::ErrorUnsupportedExportKeyFormat(); |
| 173 | } |
| 174 | |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 175 | Status AlgorithmImplementation::ExportKeyJwk( |
| 176 | const blink::WebCryptoKey& key, |
| 177 | std::vector<uint8_t>* buffer) const { |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 178 | return Status::ErrorUnsupportedExportKeyFormat(); |
| 179 | } |
| 180 | |
eroman | a895fed | 2014-11-08 03:10:25 | [diff] [blame] | 181 | Status AlgorithmImplementation::SerializeKeyForClone( |
| 182 | const blink::WebCryptoKey& key, |
| 183 | blink::WebVector<uint8_t>* key_data) const { |
| 184 | return Status::ErrorUnsupported(); |
| 185 | } |
| 186 | |
| 187 | Status AlgorithmImplementation::DeserializeKeyForClone( |
| 188 | const blink::WebCryptoKeyAlgorithm& algorithm, |
| 189 | blink::WebCryptoKeyType type, |
| 190 | bool extractable, |
| 191 | blink::WebCryptoKeyUsageMask usages, |
| 192 | const CryptoData& key_data, |
| 193 | blink::WebCryptoKey* key) const { |
| 194 | return Status::ErrorUnsupported(); |
| 195 | } |
| 196 | |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 197 | } // namespace webcrypto |