OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "components/gcm_driver/crypto/gcm_encryption_provider.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "components/gcm_driver/crypto/gcm_key_store.h" |
| 10 #include "components/gcm_driver/crypto/proto/gcm_encryption_data.pb.h" |
| 11 |
| 12 namespace gcm { |
| 13 |
| 14 GCMEncryptionProvider::GCMEncryptionProvider() |
| 15 : weak_ptr_factory_(this) { |
| 16 } |
| 17 |
| 18 GCMEncryptionProvider::~GCMEncryptionProvider() { |
| 19 } |
| 20 |
| 21 void GCMEncryptionProvider::Init( |
| 22 const base::FilePath& store_path, |
| 23 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { |
| 24 DCHECK(!key_store_); |
| 25 key_store_ = new GCMKeyStore(store_path, blocking_task_runner); |
| 26 } |
| 27 |
| 28 void GCMEncryptionProvider::GetPublicKey(const std::string& app_id, |
| 29 const PublicKeyCallback& callback) { |
| 30 DCHECK(key_store_); |
| 31 key_store_->GetKeys( |
| 32 app_id, base::Bind(&GCMEncryptionProvider::DidGetPublicKey, |
| 33 weak_ptr_factory_.GetWeakPtr(), app_id, callback)); |
| 34 } |
| 35 |
| 36 void GCMEncryptionProvider::DidGetPublicKey(const std::string& app_id, |
| 37 const PublicKeyCallback& callback, |
| 38 const KeyPair& pair) { |
| 39 if (!pair.IsInitialized()) { |
| 40 key_store_->CreateKeys( |
| 41 app_id, base::Bind(&GCMEncryptionProvider::DidCreatePublicKey, |
| 42 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 43 return; |
| 44 } |
| 45 |
| 46 DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type()); |
| 47 callback.Run(pair.public_key()); |
| 48 } |
| 49 |
| 50 void GCMEncryptionProvider::DidCreatePublicKey( |
| 51 const PublicKeyCallback& callback, |
| 52 const KeyPair& pair) { |
| 53 if (!pair.IsInitialized()) { |
| 54 callback.Run(std::string()); |
| 55 return; |
| 56 } |
| 57 |
| 58 DCHECK_EQ(KeyPair::ECDH_CURVE_25519, pair.type()); |
| 59 callback.Run(pair.public_key()); |
| 60 } |
| 61 |
| 62 } // namespace gcm |
OLD | NEW |