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

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

Issue 1158923005: Use the exact-width integer types defined in <stdint.h> rather than (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak comments. Exclude mime_sniffer*. Rebase. Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/x509_util_openssl.h" 5 #include "net/cert/x509_util_openssl.h"
6 6
7 #include <openssl/asn1.h> 7 #include <openssl/asn1.h>
8 #include <openssl/mem.h> 8 #include <openssl/mem.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // Jan 1st, 10000 respectively. Done by using the pre-computed numbers 208 // Jan 1st, 10000 respectively. Done by using the pre-computed numbers
209 // of days between these dates and the Unix epoch, i.e. Jan 1st, 1970, 209 // of days between these dates and the Unix epoch, i.e. Jan 1st, 1970,
210 // using the following Python script: 210 // using the following Python script:
211 // 211 //
212 // from datetime import date as D 212 // from datetime import date as D
213 // print (D(1970,1,1)-D(1,1,1)) # -> 719162 days 213 // print (D(1970,1,1)-D(1,1,1)) # -> 719162 days
214 // print (D(9999,12,31)-D(1970,1,1)) # -> 2932896 days 214 // print (D(9999,12,31)-D(1970,1,1)) # -> 2932896 days
215 // 215 //
216 // Note: This ignores leap seconds, but should be enough in practice. 216 // Note: This ignores leap seconds, but should be enough in practice.
217 // 217 //
218 const int64 kDaysFromYear0001ToUnixEpoch = 719162; 218 const int64_t kDaysFromYear0001ToUnixEpoch = 719162;
219 const int64 kDaysFromUnixEpochToYear10000 = 2932896 + 1; 219 const int64_t kDaysFromUnixEpochToYear10000 = 2932896 + 1;
220 const base::Time kEpoch = base::Time::UnixEpoch(); 220 const base::Time kEpoch = base::Time::UnixEpoch();
221 const base::Time kYear0001 = kEpoch - 221 const base::Time kYear0001 = kEpoch -
222 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch); 222 base::TimeDelta::FromDays(kDaysFromYear0001ToUnixEpoch);
223 const base::Time kYear10000 = kEpoch + 223 const base::Time kYear10000 = kEpoch +
224 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000); 224 base::TimeDelta::FromDays(kDaysFromUnixEpochToYear10000);
225 225
226 if (not_valid_before < kYear0001 || not_valid_before >= kYear10000 || 226 if (not_valid_before < kYear0001 || not_valid_before >= kYear10000 ||
227 not_valid_after < kYear0001 || not_valid_after >= kYear10000) 227 not_valid_after < kYear0001 || not_valid_after >= kYear10000)
228 return false; 228 return false;
229 229
230 return true; 230 return true;
231 } 231 }
232 232
233 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key, 233 bool CreateSelfSignedCert(crypto::RSAPrivateKey* key,
234 DigestAlgorithm alg, 234 DigestAlgorithm alg,
235 const std::string& common_name, 235 const std::string& common_name,
236 uint32 serial_number, 236 uint32_t serial_number,
237 base::Time not_valid_before, 237 base::Time not_valid_before,
238 base::Time not_valid_after, 238 base::Time not_valid_after,
239 std::string* der_encoded) { 239 std::string* der_encoded) {
240 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); 240 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE);
241 ScopedX509 cert(CreateCertificate(key->key(), 241 ScopedX509 cert(CreateCertificate(key->key(),
242 alg, 242 alg,
243 common_name, 243 common_name,
244 serial_number, 244 serial_number,
245 not_valid_before, 245 not_valid_before,
246 not_valid_after)); 246 not_valid_after));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 internal_cache = new_cache.get(); 331 internal_cache = new_cache.get();
332 X509_set_ex_data(x509, x509_der_cache_index, new_cache.release()); 332 X509_set_ex_data(x509, x509_der_cache_index, new_cache.release());
333 } 333 }
334 *der_cache = base::StringPiece(internal_cache->data); 334 *der_cache = base::StringPiece(internal_cache->data);
335 return true; 335 return true;
336 } 336 }
337 337
338 } // namespace x509_util 338 } // namespace x509_util
339 339
340 } // namespace net 340 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698