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"
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"
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
,
32 return crypto::ScopedSECKEYPrivateKey(
33 SECKEY_CopyPrivateKey(private_key_
.get()));
36 bool MockOwnerKeyUtil::IsPublicKeyPresent() {
37 return !public_key_
.empty();
40 void MockOwnerKeyUtil::Clear() {
45 void MockOwnerKeyUtil::SetPublicKey(const std::vector
<uint8
>& 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());
62 private_key_
= crypto::ImportNSSKeyFromPrivateKeyInfo(
63 slot
.get(), key_exported
, false /* not permanent */);
67 } // namespace ownership