Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / child / webcrypto / openssl / key_openssl.h
blobe25eae4b80a707a714393cd8cbc4b1e0d941f817
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 #ifndef CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_
6 #define CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_
8 #include <openssl/ossl_typ.h>
9 #include <stdint.h>
10 #include <vector>
12 #include "base/macros.h"
13 #include "crypto/scoped_openssl_types.h"
14 #include "third_party/WebKit/public/platform/WebCryptoKey.h"
16 namespace content {
18 namespace webcrypto {
20 class CryptoData;
21 class AsymKeyOpenSsl;
22 class SymKeyOpenSsl;
24 // Base key class for all OpenSSL keys, used to safely cast between types. Each
25 // key maintains a copy of its serialized form in either 'raw', 'pkcs8', or
26 // 'spki' format. This is to allow structured cloning of keys synchronously from
27 // the target Blink thread without having to lock access to the key.
28 class KeyOpenSsl : public blink::WebCryptoKeyHandle {
29 public:
30 explicit KeyOpenSsl(const CryptoData& serialized_key_data);
31 virtual ~KeyOpenSsl();
33 virtual SymKeyOpenSsl* AsSymKey();
34 virtual AsymKeyOpenSsl* AsAsymKey();
36 const std::vector<uint8_t>& serialized_key_data() const {
37 return serialized_key_data_;
40 private:
41 const std::vector<uint8_t> serialized_key_data_;
44 class SymKeyOpenSsl : public KeyOpenSsl {
45 public:
46 virtual ~SymKeyOpenSsl();
47 explicit SymKeyOpenSsl(const CryptoData& raw_key_data);
49 static SymKeyOpenSsl* Cast(const blink::WebCryptoKey& key);
51 virtual SymKeyOpenSsl* AsSymKey() OVERRIDE;
53 const std::vector<uint8_t>& raw_key_data() const {
54 return serialized_key_data();
57 private:
58 DISALLOW_COPY_AND_ASSIGN(SymKeyOpenSsl);
61 class AsymKeyOpenSsl : public KeyOpenSsl {
62 public:
63 virtual ~AsymKeyOpenSsl();
64 AsymKeyOpenSsl(crypto::ScopedEVP_PKEY key,
65 const CryptoData& serialized_key_data);
67 static AsymKeyOpenSsl* Cast(const blink::WebCryptoKey& key);
69 virtual AsymKeyOpenSsl* AsAsymKey() OVERRIDE;
71 EVP_PKEY* key() { return key_.get(); }
73 private:
74 crypto::ScopedEVP_PKEY key_;
76 DISALLOW_COPY_AND_ASSIGN(AsymKeyOpenSsl);
79 } // namespace webcrypto
81 } // namespace content
83 #endif // CONTENT_CHILD_WEBCRYPTO_OPENSSL_KEY_OPENSSL_H_