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

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

Issue 552004: Style cleanup in preparation for auto-linting base/. (Closed)
Patch Set: Created 10 years, 11 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
« no previous file with comments | « base/compat_execinfo.h ('k') | base/eintr_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <iostream> 7 #include <iostream>
8 #include <list> 8 #include <list>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 const uint8 PrivateKeyInfoCodec::kRsaAlgorithmIdentifier[] = { 47 const uint8 PrivateKeyInfoCodec::kRsaAlgorithmIdentifier[] = {
48 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 48 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
49 0x05, 0x00 49 0x05, 0x00
50 }; 50 };
51 51
52 void PrivateKeyInfoCodec::PrependBytes(uint8* val, 52 void PrivateKeyInfoCodec::PrependBytes(uint8* val,
53 int start, 53 int start,
54 int num_bytes, 54 int num_bytes,
55 std::list<uint8>* data) { 55 std::list<uint8>* data) {
56 while(num_bytes > 0) { 56 while (num_bytes > 0) {
57 --num_bytes; 57 --num_bytes;
58 data->push_front(val[start + num_bytes]); 58 data->push_front(val[start + num_bytes]);
59 } 59 }
60 } 60 }
61 61
62 void PrivateKeyInfoCodec::PrependLength(size_t size, std::list<uint8>* data) { 62 void PrivateKeyInfoCodec::PrependLength(size_t size, std::list<uint8>* data) {
63 // The high bit is used to indicate whether additional octets are needed to 63 // The high bit is used to indicate whether additional octets are needed to
64 // represent the length. 64 // represent the length.
65 if (size < 0x80) { 65 if (size < 0x80) {
66 data->push_front(static_cast<uint8>(size)); 66 data->push_front(static_cast<uint8>(size));
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 int num_bytes, 281 int num_bytes,
282 std::list<uint8>* data, 282 std::list<uint8>* data,
283 bool big_endian) { 283 bool big_endian) {
284 // Reverse input if little-endian. 284 // Reverse input if little-endian.
285 std::vector<uint8> tmp; 285 std::vector<uint8> tmp;
286 if (!big_endian) { 286 if (!big_endian) {
287 tmp.assign(val, val + num_bytes); 287 tmp.assign(val, val + num_bytes);
288 reverse(tmp.begin(), tmp.end()); 288 reverse(tmp.begin(), tmp.end());
289 val = &tmp.front(); 289 val = &tmp.front();
290 } 290 }
291 291
292 // ASN.1 integers are unpadded byte arrays, so skip any null padding bytes 292 // ASN.1 integers are unpadded byte arrays, so skip any null padding bytes
293 // from the most-significant end of the integer. 293 // from the most-significant end of the integer.
294 int start = 0; 294 int start = 0;
295 while (start < (num_bytes - 1) && val[start] == 0x00) { 295 while (start < (num_bytes - 1) && val[start] == 0x00) {
296 start++; 296 start++;
297 num_bytes--; 297 num_bytes--;
298 } 298 }
299 PrependBytes(val, start, num_bytes, data); 299 PrependBytes(val, start, num_bytes, data);
300 300
301 // ASN.1 integers are signed. To encode a positive integer whose sign bit 301 // ASN.1 integers are signed. To encode a positive integer whose sign bit
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 int pad = expected_size - temp.size(); 353 int pad = expected_size - temp.size();
354 int index = 0; 354 int index = 0;
355 if (out->size() == expected_size + 1) { 355 if (out->size() == expected_size + 1) {
356 READ_ASSERT(out->front() == 0x00); 356 READ_ASSERT(out->front() == 0x00);
357 pad++; 357 pad++;
358 index++; 358 index++;
359 } else { 359 } else {
360 READ_ASSERT(out->size() <= expected_size); 360 READ_ASSERT(out->size() <= expected_size);
361 } 361 }
362 362
363 while(pad) { 363 while (pad) {
364 out->push_back(0x00); 364 out->push_back(0x00);
365 pad--; 365 pad--;
366 } 366 }
367 out->insert(out->end(), temp.begin(), temp.end()); 367 out->insert(out->end(), temp.begin(), temp.end());
368 368
369 // Reverse output if little-endian. 369 // Reverse output if little-endian.
370 if (!big_endian_) 370 if (!big_endian_)
371 reverse(out->begin(), out->end()); 371 reverse(out->begin(), out->end());
372 return true; 372 return true;
373 } 373 }
374 374
375 } // namespace base 375 } // namespace base
OLDNEW
« no previous file with comments | « base/compat_execinfo.h ('k') | base/eintr_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698