| 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 "net/ssl/ssl_platform_key_util.h" | 5 #include "net/ssl/ssl_platform_key_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "net/cert/x509_certificate.h" | 10 #include "net/cert/x509_certificate.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 scoped_refptr<X509Certificate> cert = | 24 scoped_refptr<X509Certificate> cert = |
| 25 ImportCertFromFile(GetTestCertsDirectory(), filename); | 25 ImportCertFromFile(GetTestCertsDirectory(), filename); |
| 26 if (!cert) { | 26 if (!cert) { |
| 27 ADD_FAILURE() << "Could not read " << filename; | 27 ADD_FAILURE() << "Could not read " << filename; |
| 28 return false; | 28 return false; |
| 29 } | 29 } |
| 30 | 30 |
| 31 return GetClientCertInfo(cert.get(), out_type, out_max_length); | 31 return GetClientCertInfo(cert.get(), out_type, out_max_length); |
| 32 } | 32 } |
| 33 | 33 |
| 34 size_t BitsToBytes(size_t bits) { |
| 35 return (bits + 7) / 8; |
| 36 } |
| 37 |
| 34 } // namespace | 38 } // namespace |
| 35 | 39 |
| 36 TEST(SSLPlatformKeyUtil, GetClientCertInfo) { | 40 TEST(SSLPlatformKeyUtil, GetClientCertInfo) { |
| 37 SSLPrivateKey::Type type; | 41 SSLPrivateKey::Type type; |
| 38 size_t max_length; | 42 size_t max_length; |
| 39 | 43 |
| 40 ASSERT_TRUE(GetClientCertInfoFromFile("client_1.pem", &type, &max_length)); | 44 ASSERT_TRUE(GetClientCertInfoFromFile("client_1.pem", &type, &max_length)); |
| 41 EXPECT_EQ(SSLPrivateKey::Type::RSA, type); | 45 EXPECT_EQ(SSLPrivateKey::Type::RSA, type); |
| 42 EXPECT_EQ(2048u / 8u, max_length); | 46 EXPECT_EQ(2048u / 8u, max_length); |
| 43 | 47 |
| 44 ASSERT_TRUE(GetClientCertInfoFromFile("client_4.pem", &type, &max_length)); | 48 ASSERT_TRUE(GetClientCertInfoFromFile("client_4.pem", &type, &max_length)); |
| 45 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P256, type); | 49 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P256, type); |
| 46 EXPECT_EQ(ECDSA_SIG_max_len(256u / 8u), max_length); | 50 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(256)), max_length); |
| 51 |
| 52 ASSERT_TRUE(GetClientCertInfoFromFile("client_5.pem", &type, &max_length)); |
| 53 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P384, type); |
| 54 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(384)), max_length); |
| 55 |
| 56 ASSERT_TRUE(GetClientCertInfoFromFile("client_6.pem", &type, &max_length)); |
| 57 EXPECT_EQ(SSLPrivateKey::Type::ECDSA_P521, type); |
| 58 EXPECT_EQ(ECDSA_SIG_max_len(BitsToBytes(521)), max_length); |
| 47 } | 59 } |
| 48 | 60 |
| 49 } // namespace net | 61 } // namespace net |
| OLD | NEW |