Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: net/ssl/ssl_private_key_test_util.cc

Issue 2575683003: Fix SignWithOpenSSL in SSLPrivateKey tests. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_private_key_test_util.h" 5 #include "net/ssl/ssl_private_key_test_util.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return false; 110 return false;
111 } 111 }
112 112
113 return true; 113 return true;
114 } 114 }
115 115
116 bool SignWithOpenSSL(const EVP_MD* md, 116 bool SignWithOpenSSL(const EVP_MD* md,
117 const base::StringPiece& digest, 117 const base::StringPiece& digest,
118 EVP_PKEY* key, 118 EVP_PKEY* key,
119 std::string* result) { 119 std::string* result) {
120 size_t sig_len; 120 size_t sig_len = EVP_PKEY_size(key);
121 bssl::UniquePtr<EVP_PKEY_CTX> ctx(EVP_PKEY_CTX_new(key, nullptr)); 121 bssl::UniquePtr<EVP_PKEY_CTX> ctx(EVP_PKEY_CTX_new(key, nullptr));
122 if (!ctx || !EVP_PKEY_sign_init(ctx.get()) || 122 if (!ctx || !EVP_PKEY_sign_init(ctx.get()) ||
123 !EVP_PKEY_CTX_set_signature_md(ctx.get(), md) || 123 !EVP_PKEY_CTX_set_signature_md(ctx.get(), md) ||
124 !EVP_PKEY_sign(ctx.get(), OpenSSLWriteInto(result, EVP_PKEY_size(key)), 124 !EVP_PKEY_sign(ctx.get(), OpenSSLWriteInto(result, sig_len), &sig_len,
125 &sig_len, reinterpret_cast<const uint8_t*>(digest.data()), 125 reinterpret_cast<const uint8_t*>(digest.data()),
126 digest.size())) { 126 digest.size())) {
127 return false; 127 return false;
128 } 128 }
129 129
130 result->resize(sig_len); 130 result->resize(sig_len);
131 return true; 131 return true;
132 } 132 }
133 133
134 void OnSignComplete(base::RunLoop* loop, 134 void OnSignComplete(base::RunLoop* loop,
135 Error* out_error, 135 Error* out_error,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 if (key->GetType() == SSLPrivateKey::Type::RSA) { 212 if (key->GetType() == SSLPrivateKey::Type::RSA) {
213 std::string openssl_signature; 213 std::string openssl_signature;
214 ASSERT_TRUE( 214 ASSERT_TRUE(
215 SignWithOpenSSL(md, digest, openssl_key.get(), &openssl_signature)); 215 SignWithOpenSSL(md, digest, openssl_key.get(), &openssl_signature));
216 EXPECT_EQ(openssl_signature, signature); 216 EXPECT_EQ(openssl_signature, signature);
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 } // namespace net 221 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698