| Index: net/test/cert_test_util_nss.cc
|
| diff --git a/net/test/cert_test_util_nss.cc b/net/test/cert_test_util_nss.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..afa9cb2391a984ceb2aa21a784f26003238424ff
|
| --- /dev/null
|
| +++ b/net/test/cert_test_util_nss.cc
|
| @@ -0,0 +1,38 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "net/test/cert_test_util.h"
|
| +
|
| +#include "base/file_util.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/path_service.h"
|
| +
|
| +namespace net {
|
| +
|
| +scoped_ptr<crypto::RSAPrivateKey> ImportSensitiveKeyFromFile(
|
| + const base::FilePath& dir,
|
| + const std::string& key_filename,
|
| + PK11SlotInfo* slot) {
|
| + base::FilePath key_path = dir.AppendASCII(key_filename);
|
| + std::string key_pkcs8;
|
| + bool success = base::ReadFileToString(key_path, &key_pkcs8);
|
| + if (!success) {
|
| + LOG(ERROR) << "Failed to read file " << key_path.value();
|
| + return scoped_ptr<crypto::RSAPrivateKey>();
|
| + }
|
| +
|
| + const uint8* key_pkcs8_begin =
|
| + reinterpret_cast<const uint8*>(key_pkcs8.data());
|
| + std::vector<uint8> key_vector(key_pkcs8_begin,
|
| + key_pkcs8_begin + key_pkcs8.length());
|
| +
|
| + scoped_ptr<crypto::RSAPrivateKey> private_key(
|
| + crypto::RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(slot,
|
| + key_vector));
|
| + LOG_IF(ERROR, !private_key) << "Could not create key from file "
|
| + << key_path.value();
|
| + return private_key.Pass();
|
| +}
|
| +
|
| +} // namespace net
|
|
|