OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "content/child/webcrypto/openssl/key_openssl.h" |
| 6 |
5 #include "content/child/webcrypto/crypto_data.h" | 7 #include "content/child/webcrypto/crypto_data.h" |
| 8 #include "content/child/webcrypto/status.h" |
| 9 #include "content/child/webcrypto/webcrypto_util.h" |
6 | 10 |
7 namespace content { | 11 namespace content { |
8 | 12 |
9 namespace webcrypto { | 13 namespace webcrypto { |
10 | 14 |
11 CryptoData::CryptoData() : bytes_(NULL), byte_length_(0) {} | 15 KeyOpenSsl::KeyOpenSsl(const CryptoData& serialized_key_data) |
| 16 : serialized_key_data_( |
| 17 serialized_key_data.bytes(), |
| 18 serialized_key_data.bytes() + serialized_key_data.byte_length()) { |
| 19 } |
12 | 20 |
13 CryptoData::CryptoData(const unsigned char* bytes, unsigned int byte_length) | 21 KeyOpenSsl::~KeyOpenSsl() { |
14 : bytes_(bytes), byte_length_(byte_length) {} | 22 } |
15 | 23 |
16 CryptoData::CryptoData(const std::vector<unsigned char>& bytes) | 24 SymKeyOpenSsl* KeyOpenSsl::AsSymKey() { |
17 : bytes_(bytes.size() ? &bytes[0] : NULL), byte_length_(bytes.size()) {} | 25 return NULL; |
| 26 } |
18 | 27 |
19 CryptoData::CryptoData(const std::string& bytes) | 28 SymKeyOpenSsl::~SymKeyOpenSsl() { |
20 : bytes_(bytes.size() ? reinterpret_cast<const unsigned char*>(bytes.data()) | 29 } |
21 : NULL), | |
22 byte_length_(bytes.size()) {} | |
23 | 30 |
24 CryptoData::CryptoData(const blink::WebVector<unsigned char>& bytes) | 31 SymKeyOpenSsl* SymKeyOpenSsl::Cast(const blink::WebCryptoKey& key) { |
25 : bytes_(bytes.data()), byte_length_(bytes.size()) {} | 32 KeyOpenSsl* platform_key = reinterpret_cast<KeyOpenSsl*>(key.handle()); |
| 33 return platform_key->AsSymKey(); |
| 34 } |
| 35 |
| 36 SymKeyOpenSsl* SymKeyOpenSsl::AsSymKey() { |
| 37 return this; |
| 38 } |
| 39 |
| 40 SymKeyOpenSsl::SymKeyOpenSsl(const CryptoData& raw_key_data) |
| 41 : KeyOpenSsl(raw_key_data) { |
| 42 } |
| 43 |
| 44 bool PlatformSerializeKeyForClone(const blink::WebCryptoKey& key, |
| 45 blink::WebVector<uint8>* key_data) { |
| 46 const KeyOpenSsl* openssl_key = static_cast<KeyOpenSsl*>(key.handle()); |
| 47 *key_data = openssl_key->serialized_key_data(); |
| 48 return true; |
| 49 } |
26 | 50 |
27 } // namespace webcrypto | 51 } // namespace webcrypto |
28 | 52 |
29 } // namespace content | 53 } // namespace content |
OLD | NEW |