Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / ownership / mock_owner_key_util.cc
blob5b28c785e001b71d364b78f223dc07e1250c2767
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/nss_util.h"
13 #include "crypto/rsa_private_key.h"
15 namespace ownership {
17 MockOwnerKeyUtil::MockOwnerKeyUtil() {
20 MockOwnerKeyUtil::~MockOwnerKeyUtil() {
23 bool MockOwnerKeyUtil::ImportPublicKey(std::vector<uint8>* output) {
24 *output = public_key_;
25 return !public_key_.empty();
28 crypto::ScopedSECKEYPrivateKey MockOwnerKeyUtil::FindPrivateKeyInSlot(
29 const std::vector<uint8>& key,
30 PK11SlotInfo* slot) {
31 if (!private_key_)
32 return nullptr;
33 return crypto::ScopedSECKEYPrivateKey(
34 SECKEY_CopyPrivateKey(private_key_.get()));
37 bool MockOwnerKeyUtil::IsPublicKeyPresent() {
38 return !public_key_.empty();
41 void MockOwnerKeyUtil::Clear() {
42 public_key_.clear();
43 private_key_.reset();
46 void MockOwnerKeyUtil::SetPublicKey(const std::vector<uint8>& key) {
47 public_key_ = key;
50 void MockOwnerKeyUtil::SetPublicKeyFromPrivateKey(
51 const crypto::RSAPrivateKey& key) {
52 CHECK(key.ExportPublicKey(&public_key_));
55 void MockOwnerKeyUtil::SetPrivateKey(scoped_ptr<crypto::RSAPrivateKey> key) {
56 crypto::EnsureNSSInit();
58 CHECK(key->ExportPublicKey(&public_key_));
60 std::vector<uint8_t> key_exported;
61 CHECK(key->ExportPrivateKey(&key_exported));
63 crypto::ScopedPK11Slot slot(PK11_GetInternalSlot());
64 CHECK(slot);
65 private_key_ = crypto::ImportNSSKeyFromPrivateKeyInfo(
66 slot.get(), key_exported, false /* not permanent */);
67 CHECK(private_key_);
70 } // namespace ownership