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>
12 #include "base/macros.h"
13 #include "crypto/scoped_openssl_types.h"
14 #include "third_party/WebKit/public/platform/WebCryptoKey.h"
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
{
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_
;
41 const std::vector
<uint8_t> serialized_key_data_
;
44 class SymKeyOpenSsl
: public KeyOpenSsl
{
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();
58 DISALLOW_COPY_AND_ASSIGN(SymKeyOpenSsl
);
61 class AsymKeyOpenSsl
: public KeyOpenSsl
{
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(); }
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_