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/nss_util.h"
13 #include "crypto/rsa_private_key.h"
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
,
33 return crypto::ScopedSECKEYPrivateKey(
34 SECKEY_CopyPrivateKey(private_key_
.get()));
37 bool MockOwnerKeyUtil::IsPublicKeyPresent() {
38 return !public_key_
.empty();
41 void MockOwnerKeyUtil::Clear() {
46 void MockOwnerKeyUtil::SetPublicKey(const std::vector
<uint8
>& 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());
65 private_key_
= crypto::ImportNSSKeyFromPrivateKeyInfo(
66 slot
.get(), key_exported
, false /* not permanent */);
70 } // namespace ownership