Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / components / ownership / mock_owner_key_util.cc
blob3f5adb58c6e0a13180303d65491fcb12f8b2b93f
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.
5 #include "components/ownership/mock_owner_key_util.h"
7 #include <pk11pub.h>
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "crypto/nss_key_util.h"
12 #include "crypto/rsa_private_key.h"
14 namespace ownership {
16 MockOwnerKeyUtil::MockOwnerKeyUtil() {
19 MockOwnerKeyUtil::~MockOwnerKeyUtil() {
22 bool MockOwnerKeyUtil::ImportPublicKey(std::vector<uint8>* output) {
23 *output = public_key_;
24 return !public_key_.empty();
27 crypto::ScopedSECKEYPrivateKey MockOwnerKeyUtil::FindPrivateKeyInSlot(
28 const std::vector<uint8>& key,
29 PK11SlotInfo* slot) {
30 if (!private_key_)
31 return nullptr;
32 return crypto::ScopedSECKEYPrivateKey(
33 SECKEY_CopyPrivateKey(private_key_.get()));
36 bool MockOwnerKeyUtil::IsPublicKeyPresent() {
37 return !public_key_.empty();
40 void MockOwnerKeyUtil::Clear() {
41 public_key_.clear();
42 private_key_.reset();
45 void MockOwnerKeyUtil::SetPublicKey(const std::vector<uint8>& key) {
46 public_key_ = key;
49 void MockOwnerKeyUtil::SetPublicKeyFromPrivateKey(
50 const crypto::RSAPrivateKey& key) {
51 CHECK(key.ExportPublicKey(&public_key_));
54 void MockOwnerKeyUtil::SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key) {
55 CHECK(key->ExportPublicKey(&public_key_));
57 std::vector<uint8_t> key_exported;
58 CHECK(key->ExportPrivateKey(&key_exported));
60 crypto::ScopedPK11Slot slot(PK11_GetInternalSlot());
61 CHECK(slot);
62 private_key_ = crypto::ImportNSSKeyFromPrivateKeyInfo(
63 slot.get(), key_exported, false /* not permanent */);
64 CHECK(private_key_);
67 } // namespace ownership