1 // Copyright (c) 2012 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/ownership/mock_owner_key_util.h" 6 7 #include "base/files/file_path.h" 8 #include "crypto/rsa_private_key.h" 9 10 namespace ownership { 11 MockOwnerKeyUtil()12MockOwnerKeyUtil::MockOwnerKeyUtil() { 13 } 14 ~MockOwnerKeyUtil()15MockOwnerKeyUtil::~MockOwnerKeyUtil() { 16 } 17 ImportPublicKey(std::vector<uint8> * output)18bool MockOwnerKeyUtil::ImportPublicKey(std::vector<uint8>* output) { 19 *output = public_key_; 20 return !public_key_.empty(); 21 } 22 23 #if defined(USE_NSS) FindPrivateKeyInSlot(const std::vector<uint8> & key,PK11SlotInfo * slot)24crypto::RSAPrivateKey* MockOwnerKeyUtil::FindPrivateKeyInSlot( 25 const std::vector<uint8>& key, 26 PK11SlotInfo* slot) { 27 return private_key_.get() ? private_key_->Copy() : NULL; 28 } 29 #endif // defined(USE_NSS) 30 IsPublicKeyPresent()31bool MockOwnerKeyUtil::IsPublicKeyPresent() { 32 return !public_key_.empty(); 33 } 34 Clear()35void MockOwnerKeyUtil::Clear() { 36 public_key_.clear(); 37 private_key_.reset(); 38 } 39 SetPublicKey(const std::vector<uint8> & key)40void MockOwnerKeyUtil::SetPublicKey(const std::vector<uint8>& key) { 41 public_key_ = key; 42 } 43 SetPublicKeyFromPrivateKey(const crypto::RSAPrivateKey & key)44void MockOwnerKeyUtil::SetPublicKeyFromPrivateKey( 45 const crypto::RSAPrivateKey& key) { 46 key.ExportPublicKey(&public_key_); 47 } 48 SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key)49void MockOwnerKeyUtil::SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key) { 50 private_key_ = key.Pass(); 51 private_key_->ExportPublicKey(&public_key_); 52 } 53 54 } // namespace ownership 55