Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / webcrypto / algorithm_implementation.cc
blob5f54791dbdaf7504f137b68ede6ed086a9a97196
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.
5 #include "components/webcrypto/algorithm_implementation.h"
7 #include "components/webcrypto/key.h"
8 #include "components/webcrypto/status.h"
10 namespace webcrypto {
12 AlgorithmImplementation::~AlgorithmImplementation() {
15 Status AlgorithmImplementation::Encrypt(
16 const blink::WebCryptoAlgorithm& algorithm,
17 const blink::WebCryptoKey& key,
18 const CryptoData& data,
19 std::vector<uint8_t>* buffer) const {
20 return Status::ErrorUnsupported();
23 Status AlgorithmImplementation::Decrypt(
24 const blink::WebCryptoAlgorithm& algorithm,
25 const blink::WebCryptoKey& key,
26 const CryptoData& data,
27 std::vector<uint8_t>* buffer) const {
28 return Status::ErrorUnsupported();
31 Status AlgorithmImplementation::Sign(const blink::WebCryptoAlgorithm& algorithm,
32 const blink::WebCryptoKey& key,
33 const CryptoData& data,
34 std::vector<uint8_t>* buffer) const {
35 return Status::ErrorUnsupported();
38 Status AlgorithmImplementation::Verify(
39 const blink::WebCryptoAlgorithm& algorithm,
40 const blink::WebCryptoKey& key,
41 const CryptoData& signature,
42 const CryptoData& data,
43 bool* signature_match) const {
44 return Status::ErrorUnsupported();
47 Status AlgorithmImplementation::Digest(
48 const blink::WebCryptoAlgorithm& algorithm,
49 const CryptoData& data,
50 std::vector<uint8_t>* buffer) const {
51 return Status::ErrorUnsupported();
54 Status AlgorithmImplementation::GenerateKey(
55 const blink::WebCryptoAlgorithm& algorithm,
56 bool extractable,
57 blink::WebCryptoKeyUsageMask usages,
58 GenerateKeyResult* result) const {
59 return Status::ErrorUnsupported();
62 Status AlgorithmImplementation::DeriveBits(
63 const blink::WebCryptoAlgorithm& algorithm,
64 const blink::WebCryptoKey& base_key,
65 bool has_optional_length_bits,
66 unsigned int optional_length_bits,
67 std::vector<uint8_t>* derived_bytes) const {
68 return Status::ErrorUnsupported();
71 Status AlgorithmImplementation::GetKeyLength(
72 const blink::WebCryptoAlgorithm& key_length_algorithm,
73 bool* has_length_bits,
74 unsigned int* length_bits) const {
75 return Status::ErrorUnsupported();
78 Status AlgorithmImplementation::VerifyKeyUsagesBeforeImportKey(
79 blink::WebCryptoKeyFormat format,
80 blink::WebCryptoKeyUsageMask usages) const {
81 return Status::ErrorUnsupportedImportKeyFormat();
84 Status AlgorithmImplementation::ImportKey(
85 blink::WebCryptoKeyFormat format,
86 const CryptoData& key_data,
87 const blink::WebCryptoAlgorithm& algorithm,
88 bool extractable,
89 blink::WebCryptoKeyUsageMask usages,
90 blink::WebCryptoKey* key) const {
91 switch (format) {
92 case blink::WebCryptoKeyFormatRaw:
93 return ImportKeyRaw(key_data, algorithm, extractable, usages, key);
94 case blink::WebCryptoKeyFormatSpki:
95 return ImportKeySpki(key_data, algorithm, extractable, usages, key);
96 case blink::WebCryptoKeyFormatPkcs8:
97 return ImportKeyPkcs8(key_data, algorithm, extractable, usages, key);
98 case blink::WebCryptoKeyFormatJwk:
99 return ImportKeyJwk(key_data, algorithm, extractable, usages, key);
100 default:
101 return Status::ErrorUnsupported();
105 Status AlgorithmImplementation::ImportKeyRaw(
106 const CryptoData& key_data,
107 const blink::WebCryptoAlgorithm& algorithm,
108 bool extractable,
109 blink::WebCryptoKeyUsageMask usages,
110 blink::WebCryptoKey* key) const {
111 return Status::ErrorUnsupportedImportKeyFormat();
114 Status AlgorithmImplementation::ImportKeyPkcs8(
115 const CryptoData& key_data,
116 const blink::WebCryptoAlgorithm& algorithm,
117 bool extractable,
118 blink::WebCryptoKeyUsageMask usages,
119 blink::WebCryptoKey* key) const {
120 return Status::ErrorUnsupportedImportKeyFormat();
123 Status AlgorithmImplementation::ImportKeySpki(
124 const CryptoData& key_data,
125 const blink::WebCryptoAlgorithm& algorithm,
126 bool extractable,
127 blink::WebCryptoKeyUsageMask usages,
128 blink::WebCryptoKey* key) const {
129 return Status::ErrorUnsupportedImportKeyFormat();
132 Status AlgorithmImplementation::ImportKeyJwk(
133 const CryptoData& key_data,
134 const blink::WebCryptoAlgorithm& algorithm,
135 bool extractable,
136 blink::WebCryptoKeyUsageMask usages,
137 blink::WebCryptoKey* key) const {
138 return Status::ErrorUnsupportedImportKeyFormat();
141 Status AlgorithmImplementation::ExportKey(blink::WebCryptoKeyFormat format,
142 const blink::WebCryptoKey& key,
143 std::vector<uint8_t>* buffer) const {
144 switch (format) {
145 case blink::WebCryptoKeyFormatRaw:
146 return ExportKeyRaw(key, buffer);
147 case blink::WebCryptoKeyFormatSpki:
148 return ExportKeySpki(key, buffer);
149 case blink::WebCryptoKeyFormatPkcs8:
150 return ExportKeyPkcs8(key, buffer);
151 case blink::WebCryptoKeyFormatJwk:
152 return ExportKeyJwk(key, buffer);
153 default:
154 return Status::ErrorUnsupported();
158 Status AlgorithmImplementation::ExportKeyRaw(
159 const blink::WebCryptoKey& key,
160 std::vector<uint8_t>* buffer) const {
161 return Status::ErrorUnsupportedExportKeyFormat();
164 Status AlgorithmImplementation::ExportKeyPkcs8(
165 const blink::WebCryptoKey& key,
166 std::vector<uint8_t>* buffer) const {
167 return Status::ErrorUnsupportedExportKeyFormat();
170 Status AlgorithmImplementation::ExportKeySpki(
171 const blink::WebCryptoKey& key,
172 std::vector<uint8_t>* buffer) const {
173 return Status::ErrorUnsupportedExportKeyFormat();
176 Status AlgorithmImplementation::ExportKeyJwk(
177 const blink::WebCryptoKey& key,
178 std::vector<uint8_t>* buffer) const {
179 return Status::ErrorUnsupportedExportKeyFormat();
182 Status AlgorithmImplementation::SerializeKeyForClone(
183 const blink::WebCryptoKey& key,
184 blink::WebVector<uint8_t>* key_data) const {
185 *key_data = GetSerializedKeyData(key);
186 return Status::Success();
189 Status AlgorithmImplementation::DeserializeKeyForClone(
190 const blink::WebCryptoKeyAlgorithm& algorithm,
191 blink::WebCryptoKeyType type,
192 bool extractable,
193 blink::WebCryptoKeyUsageMask usages,
194 const CryptoData& key_data,
195 blink::WebCryptoKey* key) const {
196 return Status::ErrorUnsupported();
199 } // namespace webcrypto