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

Side by Side Diff: net/cert/pem_tokenizer.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cert/pem_tokenizer.h" 5 #include "net/cert/pem_tokenizer.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (footer_pos == StringPiece::npos) { 54 if (footer_pos == StringPiece::npos) {
55 pos_ = StringPiece::npos; 55 pos_ = StringPiece::npos;
56 return false; 56 return false;
57 } 57 }
58 58
59 // Chop off the header and footer and parse the data in between. 59 // Chop off the header and footer and parse the data in between.
60 StringPiece::size_type data_begin = pos_ + it->header.size(); 60 StringPiece::size_type data_begin = pos_ + it->header.size();
61 pos_ = footer_pos + it->footer.size(); 61 pos_ = footer_pos + it->footer.size();
62 block_type_ = it->type; 62 block_type_ = it->type;
63 63
64 StringPiece encoded = str_.substr(data_begin, 64 StringPiece encoded = str_.substr(data_begin, footer_pos - data_begin);
65 footer_pos - data_begin); 65 if (!base::Base64Decode(
66 if (!base::Base64Decode(base::CollapseWhitespaceASCII(encoded.as_string(), 66 base::CollapseWhitespaceASCII(encoded.as_string(), true),
67 true), &data_)) { 67 &data_)) {
68 // The most likely cause for a decode failure is a datatype that 68 // The most likely cause for a decode failure is a datatype that
69 // includes PEM headers, which are not supported. 69 // includes PEM headers, which are not supported.
70 break; 70 break;
71 } 71 }
72 72
73 return true; 73 return true;
74 } 74 }
75 75
76 // If the block did not match any acceptable type, move past it and 76 // If the block did not match any acceptable type, move past it and
77 // continue the search. Otherwise, |pos_| has been updated to the most 77 // continue the search. Otherwise, |pos_| has been updated to the most
78 // appropriate search position to continue searching from and should not 78 // appropriate search position to continue searching from and should not
79 // be adjusted. 79 // be adjusted.
80 if (it == block_types_.end()) 80 if (it == block_types_.end())
81 pos_ += sizeof(kPEMSearchBlock); 81 pos_ += sizeof(kPEMSearchBlock);
82 } 82 }
83 83
84 return false; 84 return false;
85 } 85 }
86 86
87 void PEMTokenizer::Init( 87 void PEMTokenizer::Init(const StringPiece& str,
88 const StringPiece& str, 88 const std::vector<std::string>& allowed_block_types) {
89 const std::vector<std::string>& allowed_block_types) {
90 str_ = str; 89 str_ = str;
91 pos_ = 0; 90 pos_ = 0;
92 91
93 // Construct PEM header/footer strings for all the accepted types, to 92 // Construct PEM header/footer strings for all the accepted types, to
94 // reduce parsing later. 93 // reduce parsing later.
95 for (std::vector<std::string>::const_iterator it = 94 for (std::vector<std::string>::const_iterator it =
96 allowed_block_types.begin(); it != allowed_block_types.end(); ++it) { 95 allowed_block_types.begin();
96 it != allowed_block_types.end();
97 ++it) {
97 PEMType allowed_type; 98 PEMType allowed_type;
98 allowed_type.type = *it; 99 allowed_type.type = *it;
99 allowed_type.header = base::StringPrintf(kPEMBeginBlock, it->c_str()); 100 allowed_type.header = base::StringPrintf(kPEMBeginBlock, it->c_str());
100 allowed_type.footer = base::StringPrintf(kPEMEndBlock, it->c_str()); 101 allowed_type.footer = base::StringPrintf(kPEMEndBlock, it->c_str());
101 block_types_.push_back(allowed_type); 102 block_types_.push_back(allowed_type);
102 } 103 }
103 } 104 }
104 105
105 } // namespace net 106 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698