OLD | NEW |
| (Empty) |
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 | |
5 #ifndef CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_HASHED_ALGORITHM_OPENSSL_H_ | |
6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_HASHED_ALGORITHM_OPENSSL_H_ | |
7 | |
8 #include "content/child/webcrypto/algorithm_implementation.h" | |
9 | |
10 namespace content { | |
11 | |
12 namespace webcrypto { | |
13 | |
14 // Base class for an RSA algorithm whose keys additionaly have a hash parameter | |
15 // bound to them. Provides functionality for generating, importing, and | |
16 // exporting keys. | |
17 class RsaHashedAlgorithm : public AlgorithmImplementation { | |
18 public: | |
19 // |all_public_key_usages| and |all_private_key_usages| are the set of | |
20 // WebCrypto key usages that are valid for created keys (public and private | |
21 // respectively). | |
22 // | |
23 // For instance if public keys support encryption and wrapping, and private | |
24 // keys support decryption and unwrapping callers should set: | |
25 // all_public_key_usages = UsageEncrypt | UsageWrap | |
26 // all_private_key_usages = UsageDecrypt | UsageUnwrap | |
27 // This information is used when importing or generating keys, to enforce | |
28 // that valid key usages are allowed. | |
29 RsaHashedAlgorithm(blink::WebCryptoKeyUsageMask all_public_key_usages, | |
30 blink::WebCryptoKeyUsageMask all_private_key_usages) | |
31 : all_public_key_usages_(all_public_key_usages), | |
32 all_private_key_usages_(all_private_key_usages) {} | |
33 | |
34 // For instance "RSA-OAEP-256". | |
35 virtual const char* GetJwkAlgorithm( | |
36 const blink::WebCryptoAlgorithmId hash) const = 0; | |
37 | |
38 Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm, | |
39 bool extractable, | |
40 blink::WebCryptoKeyUsageMask usages, | |
41 GenerateKeyResult* result) const override; | |
42 | |
43 Status VerifyKeyUsagesBeforeImportKey( | |
44 blink::WebCryptoKeyFormat format, | |
45 blink::WebCryptoKeyUsageMask usages) const override; | |
46 | |
47 Status ImportKeyPkcs8(const CryptoData& key_data, | |
48 const blink::WebCryptoAlgorithm& algorithm, | |
49 bool extractable, | |
50 blink::WebCryptoKeyUsageMask usages, | |
51 blink::WebCryptoKey* key) const override; | |
52 | |
53 Status ImportKeySpki(const CryptoData& key_data, | |
54 const blink::WebCryptoAlgorithm& algorithm, | |
55 bool extractable, | |
56 blink::WebCryptoKeyUsageMask usages, | |
57 blink::WebCryptoKey* key) const override; | |
58 | |
59 Status ImportKeyJwk(const CryptoData& key_data, | |
60 const blink::WebCryptoAlgorithm& algorithm, | |
61 bool extractable, | |
62 blink::WebCryptoKeyUsageMask usages, | |
63 blink::WebCryptoKey* key) const override; | |
64 | |
65 Status ExportKeyPkcs8(const blink::WebCryptoKey& key, | |
66 std::vector<uint8_t>* buffer) const override; | |
67 | |
68 Status ExportKeySpki(const blink::WebCryptoKey& key, | |
69 std::vector<uint8_t>* buffer) const override; | |
70 | |
71 Status ExportKeyJwk(const blink::WebCryptoKey& key, | |
72 std::vector<uint8_t>* buffer) const override; | |
73 | |
74 Status SerializeKeyForClone( | |
75 const blink::WebCryptoKey& key, | |
76 blink::WebVector<uint8_t>* key_data) const override; | |
77 | |
78 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm, | |
79 blink::WebCryptoKeyType type, | |
80 bool extractable, | |
81 blink::WebCryptoKeyUsageMask usages, | |
82 const CryptoData& key_data, | |
83 blink::WebCryptoKey* key) const override; | |
84 | |
85 private: | |
86 const blink::WebCryptoKeyUsageMask all_public_key_usages_; | |
87 const blink::WebCryptoKeyUsageMask all_private_key_usages_; | |
88 }; | |
89 | |
90 } // namespace webcrypto | |
91 | |
92 } // namespace content | |
93 | |
94 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_RSA_HASHED_ALGORITHM_OPENSSL_H_ | |
OLD | NEW |