OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/cast_certificate/cast_cert_validator_test_helpers.h" | 5 #include "components/cast_certificate/cast_cert_validator_test_helpers.h" |
6 | 6 |
| 7 #include "net/cert/internal/cert_errors.h" |
7 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
9 #include "net/cert/pem_tokenizer.h" | 10 #include "net/cert/pem_tokenizer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace cast_certificate { | 13 namespace cast_certificate { |
13 | 14 |
14 namespace testing { | 15 namespace testing { |
15 | 16 |
16 std::string ReadTestFileToString(const base::StringPiece& file_name) { | 17 std::string ReadTestFileToString(const base::StringPiece& file_name) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 EXPECT_FALSE(result.message.empty()); | 77 EXPECT_FALSE(result.message.empty()); |
77 EXPECT_FALSE(result.signature_sha1.empty()); | 78 EXPECT_FALSE(result.signature_sha1.empty()); |
78 EXPECT_FALSE(result.signature_sha256.empty()); | 79 EXPECT_FALSE(result.signature_sha256.empty()); |
79 | 80 |
80 return result; | 81 return result; |
81 } | 82 } |
82 | 83 |
| 84 std::unique_ptr<net::TrustStoreInMemory> CreateTrustStoreFromFile( |
| 85 const std::string& path) { |
| 86 std::unique_ptr<net::TrustStoreInMemory> trust_store( |
| 87 new net::TrustStoreInMemory()); |
| 88 const auto trusted_test_roots = |
| 89 cast_certificate::testing::ReadCertificateChainFromFile(path); |
| 90 for (const auto& trusted_root : trusted_test_roots) { |
| 91 net::CertErrors errors; |
| 92 scoped_refptr<net::ParsedCertificate> cert( |
| 93 net::ParsedCertificate::Create(trusted_root, {}, &errors)); |
| 94 EXPECT_TRUE(cert) << errors.ToDebugString(); |
| 95 scoped_refptr<net::TrustAnchor> anchor = |
| 96 net::TrustAnchor::CreateFromCertificateWithConstraints(std::move(cert)); |
| 97 trust_store->AddTrustAnchor(std::move(anchor)); |
| 98 } |
| 99 return trust_store; |
| 100 } |
| 101 |
| 102 base::Time ConvertUnixTimestampSeconds(uint64_t time) { |
| 103 return base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(time); |
| 104 } |
| 105 |
83 } // namespace testing | 106 } // namespace testing |
84 | 107 |
85 } // namespace cast_certificate | 108 } // namespace cast_certificate |
OLD | NEW |