Chromium Code Reviews| Index: components/gcm_driver/crypto/gcm_encryption_handler.cc |
| diff --git a/components/gcm_driver/crypto/gcm_encryption_handler.cc b/components/gcm_driver/crypto/gcm_encryption_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba0fd8c70503a0adf2ab488300b5ab369282e688 |
| --- /dev/null |
| +++ b/components/gcm_driver/crypto/gcm_encryption_handler.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/gcm_driver/crypto/gcm_encryption_handler.h" |
| + |
| +#include "base/bind.h" |
| +#include "components/gcm_driver/crypto/gcm_key_store.h" |
| +#include "components/gcm_driver/crypto/proto/gcm_encryption_data.pb.h" |
| + |
| +namespace gcm { |
| + |
| +GCMEncryptionHandler::GCMEncryptionHandler( |
| + const base::FilePath& store_path, |
| + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner) |
| + : key_store_(new GCMKeyStore(store_path, blocking_task_runner)), |
| + weak_ptr_factory_(this) { |
| +} |
| + |
| +GCMEncryptionHandler::~GCMEncryptionHandler() { |
| +} |
| + |
| +void GCMEncryptionHandler::GetPublicEncryptionKey(const std::string& app_id, |
| + const KeyCallback& callback) { |
| + key_store_->GetKeys( |
| + app_id, base::Bind(&GCMEncryptionHandler::DidGetPublicEncryptionKey, |
| + weak_ptr_factory_.GetWeakPtr(), app_id, callback)); |
| +} |
| + |
| +void GCMEncryptionHandler::DidGetPublicEncryptionKey( |
| + const std::string& app_id, |
| + const KeyCallback& callback, |
| + const KeyPair& pair) { |
| + if (!pair.IsInitialized()) { |
| + key_store_->CreateKeys( |
|
jianli
2015/07/17 20:55:21
If GCMEncryptionHandler is the only consumer of GC
Peter Beverloo
2015/07/20 17:55:53
Agreed. I implemented the distinction because it'd
|
| + app_id, base::Bind(&GCMEncryptionHandler::DidCreatePublicEncryptionKey, |
| + weak_ptr_factory_.GetWeakPtr(), callback)); |
| + return; |
| + } |
| + |
| + DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type()); |
|
jianli
2015/07/17 20:55:21
nit: include base/logging.h
Peter Beverloo
2015/07/20 17:55:53
Done.
|
| + const std::string& public_key = pair.public_key(); |
| + |
| + callback.Run(std::vector<uint8_t>(public_key.begin(), public_key.end())); |
|
jianli
2015/07/17 20:55:21
Can we avoid the conversion?
Peter Beverloo
2015/07/20 17:55:53
Moved it to PushMessagingServiceImpl (as we're usi
|
| +} |
| + |
| +void GCMEncryptionHandler::DidCreatePublicEncryptionKey( |
| + const KeyCallback& callback, |
| + const KeyPair& pair) { |
| + if (!pair.IsInitialized()) { |
| + callback.Run(std::vector<uint8_t>()); |
| + return; |
| + } |
| + |
| + DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type()); |
| + const std::string& public_key = pair.public_key(); |
| + |
| + callback.Run(std::vector<uint8_t>(public_key.begin(), public_key.end())); |
| +} |
| + |
| +} // namespace gcm |