1 // Copyright 2015 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 COMPONENTS_WEBCRYPTO_KEY_H_
6 #define COMPONENTS_WEBCRYPTO_KEY_H_
8 #include <openssl/base.h>
13 #include "crypto/scoped_openssl_types.h"
14 #include "third_party/WebKit/public/platform/WebCryptoKey.h"
20 // Returns a reference to the symmetric key data wrapped by the given Blink
21 // key. The returned reference is owned by |key|. This function must only be
22 // called on secret keys (HMAC, AES, etc).
23 const std::vector
<uint8_t>& GetSymmetricKeyData(const blink::WebCryptoKey
& key
);
25 // Returns the EVP_PKEY* wrapped by the given Blink key. The returned pointer
26 // is owned by |key|. This function must only be called on asymmetric keys
28 EVP_PKEY
* GetEVP_PKEY(const blink::WebCryptoKey
& key
);
30 // Returns a reference to the serialized key data. This reference is owned by
31 // |key|. This function can be called for any key type.
32 const std::vector
<uint8_t>& GetSerializedKeyData(
33 const blink::WebCryptoKey
& key
);
35 // Creates a symmetric key handle that can be passed to Blink. The caller takes
36 // ownership of the returned pointer.
37 blink::WebCryptoKeyHandle
* CreateSymmetricKeyHandle(
38 const CryptoData
& key_bytes
);
40 // Creates an asymmetric key handle that can be passed to Blink. The caller
42 // ownership of the returned pointer.
44 // TODO(eroman): This should _move_ input serialized_key_data rather than
45 // create a copy, since all the callers are passing in vectors that are later
46 // thrown away anyway.
47 blink::WebCryptoKeyHandle
* CreateAsymmetricKeyHandle(
48 crypto::ScopedEVP_PKEY pkey
,
49 const std::vector
<uint8_t>& serialized_key_data
);
51 } // namespace webcrypto
53 #endif // COMPONENTS_WEBCRYPTO_KEY_H_