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

Side by Side Diff: base/crypto/rsa_private_key.cc

Issue 6312157: Add ability to create self signed certs to mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More code cleanup Created 9 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/crypto/rsa_private_key.h" 5 #include "base/crypto/rsa_private_key.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 static_cast<int>(public_exponent_.size()), 94 static_cast<int>(public_exponent_.size()),
95 &content); 95 &content);
96 PrependInteger(&modulus_[0], static_cast<int>(modulus_.size()), &content); 96 PrependInteger(&modulus_[0], static_cast<int>(modulus_.size()), &content);
97 PrependTypeHeaderAndLength(kSequenceTag, content.size(), &content); 97 PrependTypeHeaderAndLength(kSequenceTag, content.size(), &content);
98 98
99 // Copy the sequence with n and e into a buffer. 99 // Copy the sequence with n and e into a buffer.
100 std::vector<uint8> bit_string; 100 std::vector<uint8> bit_string;
101 for (std::list<uint8>::iterator i = content.begin(); i != content.end(); ++i) 101 for (std::list<uint8>::iterator i = content.begin(); i != content.end(); ++i)
102 bit_string.push_back(*i); 102 bit_string.push_back(*i);
103 content.clear(); 103 content.clear();
104 // Add the sequence as the contents of a bit string. 104 // Add the sequence as the contents of a bit string.
Ryan Sleevi 2011/02/08 02:27:55 Lines 93-103 can be replaced with a call to Export
105 PrependBitString(&bit_string[0], static_cast<int>(bit_string.size()), 105 PrependBitString(&bit_string[0], static_cast<int>(bit_string.size()),
106 &content); 106 &content);
107 107
108 // Add the RSA algorithm OID. 108 // Add the RSA algorithm OID.
109 for (size_t i = sizeof(kRsaAlgorithmIdentifier); i > 0; --i) 109 for (size_t i = sizeof(kRsaAlgorithmIdentifier); i > 0; --i)
110 content.push_front(kRsaAlgorithmIdentifier[i - 1]); 110 content.push_front(kRsaAlgorithmIdentifier[i - 1]);
111 111
112 // Finally, wrap everything in a sequence. 112 // Finally, wrap everything in a sequence.
113 PrependTypeHeaderAndLength(kSequenceTag, content.size(), &content); 113 PrependTypeHeaderAndLength(kSequenceTag, content.size(), &content);
114 114
115 // Copy everything into the output. 115 // Copy everything into the output.
116 output->reserve(content.size()); 116 output->reserve(content.size());
117 for (std::list<uint8>::iterator i = content.begin(); i != content.end(); ++i) 117 for (std::list<uint8>::iterator i = content.begin(); i != content.end(); ++i)
118 output->push_back(*i); 118 output->push_back(*i);
119 119
120 return true; 120 return true;
121 } 121 }
122 122
123 bool PrivateKeyInfoCodec::ExportPublicKey(std::vector<uint8>* output) {
124 // Create a sequence with the modulus (n) and public exponent (e).
125 std::list<uint8> content;
126 PrependInteger(&public_exponent_[0],
127 static_cast<int>(public_exponent_.size()),
128 &content);
129 PrependInteger(&modulus_[0], static_cast<int>(modulus_.size()), &content);
130 PrependTypeHeaderAndLength(kSequenceTag, content.size(), &content);
131
132 // Copy everything into the output.
133 output->reserve(content.size());
134 for (std::list<uint8>::iterator i = content.begin(); i != content.end(); ++i)
135 output->push_back(*i);
136
137 return true;
138 }
139
123 bool PrivateKeyInfoCodec::Import(const std::vector<uint8>& input) { 140 bool PrivateKeyInfoCodec::Import(const std::vector<uint8>& input) {
124 if (input.empty()) { 141 if (input.empty()) {
125 return false; 142 return false;
126 } 143 }
127 144
128 // Parse the private key info up to the public key values, ignoring 145 // Parse the private key info up to the public key values, ignoring
129 // the subsequent private key values. 146 // the subsequent private key values.
130 uint8* src = const_cast<uint8*>(&input.front()); 147 uint8* src = const_cast<uint8*>(&input.front());
131 uint8* end = src + input.size(); 148 uint8* end = src + input.size();
132 if (!ReadSequence(&src, end) || 149 if (!ReadSequence(&src, end) ||
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 // The version should be zero. 388 // The version should be zero.
372 for (uint32 i = 0; i < length; ++i) { 389 for (uint32 i = 0; i < length; ++i) {
373 READ_ASSERT(**pos == 0x00); 390 READ_ASSERT(**pos == 0x00);
374 (*pos)++; 391 (*pos)++;
375 } 392 }
376 393
377 return true; 394 return true;
378 } 395 }
379 396
380 } // namespace base 397 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698