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

Side by Side Diff: net/cert/internal/signature_algorithm.cc

Issue 1664243002: Using == instead of Equals for der::Input comparison. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Using non-class equality. Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/internal/signature_algorithm.h" 5 #include "net/cert/internal/signature_algorithm.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
10 #include "net/der/input.h" 10 #include "net/der/input.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // } 333 // }
334 WARN_UNUSED_RESULT bool ParseHashAlgorithm(const der::Input input, 334 WARN_UNUSED_RESULT bool ParseHashAlgorithm(const der::Input input,
335 DigestAlgorithm* out) { 335 DigestAlgorithm* out) {
336 der::Input oid; 336 der::Input oid;
337 der::Input params; 337 der::Input params;
338 if (!ParseAlgorithmIdentifier(input, &oid, &params)) 338 if (!ParseAlgorithmIdentifier(input, &oid, &params))
339 return false; 339 return false;
340 340
341 DigestAlgorithm hash; 341 DigestAlgorithm hash;
342 342
343 if (oid.Equals(der::Input(kOidSha1))) { 343 if (oid == der::Input(kOidSha1)) {
344 hash = DigestAlgorithm::Sha1; 344 hash = DigestAlgorithm::Sha1;
345 } else if (oid.Equals(der::Input(kOidSha256))) { 345 } else if (oid == der::Input(kOidSha256)) {
346 hash = DigestAlgorithm::Sha256; 346 hash = DigestAlgorithm::Sha256;
347 } else if (oid.Equals(der::Input(kOidSha384))) { 347 } else if (oid == der::Input(kOidSha384)) {
348 hash = DigestAlgorithm::Sha384; 348 hash = DigestAlgorithm::Sha384;
349 } else if (oid.Equals(der::Input(kOidSha512))) { 349 } else if (oid == der::Input(kOidSha512)) {
350 hash = DigestAlgorithm::Sha512; 350 hash = DigestAlgorithm::Sha512;
351 } else { 351 } else {
352 // Unsupported digest algorithm. 352 // Unsupported digest algorithm.
353 return false; 353 return false;
354 } 354 }
355 355
356 // From RFC 5912: "PARAMS TYPE NULL ARE preferredPresent". Which is to say 356 // From RFC 5912: "PARAMS TYPE NULL ARE preferredPresent". Which is to say
357 // the can either be absent, or NULL. 357 // the can either be absent, or NULL.
358 if (!IsEmpty(params) && !IsNull(params)) 358 if (!IsEmpty(params) && !IsNull(params))
359 return false; 359 return false;
(...skipping 28 matching lines...) Expand all
388 // the only function supported is MGF1, as that is the singular mask gen 388 // the only function supported is MGF1, as that is the singular mask gen
389 // function defined by RFC 4055 / RFC 5912. 389 // function defined by RFC 4055 / RFC 5912.
390 WARN_UNUSED_RESULT bool ParseMaskGenAlgorithm(const der::Input input, 390 WARN_UNUSED_RESULT bool ParseMaskGenAlgorithm(const der::Input input,
391 DigestAlgorithm* mgf1_hash) { 391 DigestAlgorithm* mgf1_hash) {
392 der::Input oid; 392 der::Input oid;
393 der::Input params; 393 der::Input params;
394 if (!ParseAlgorithmIdentifier(input, &oid, &params)) 394 if (!ParseAlgorithmIdentifier(input, &oid, &params))
395 return false; 395 return false;
396 396
397 // MGF1 is the only supported mask generation algorithm. 397 // MGF1 is the only supported mask generation algorithm.
398 if (!oid.Equals(der::Input(kOidMgf1))) 398 if (oid != der::Input(kOidMgf1))
399 return false; 399 return false;
400 400
401 return ParseHashAlgorithm(params, mgf1_hash); 401 return ParseHashAlgorithm(params, mgf1_hash);
402 } 402 }
403 403
404 // Consumes an optional, explicitly-tagged INTEGER from |parser|, using the 404 // Consumes an optional, explicitly-tagged INTEGER from |parser|, using the
405 // indicated context-specific class number. Values greater than 32-bits will be 405 // indicated context-specific class number. Values greater than 32-bits will be
406 // rejected. 406 // rejected.
407 // 407 //
408 // Returns true on success and sets |*present| to true if the field was present. 408 // Returns true on success and sets |*present| to true if the field was present.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 scoped_ptr<SignatureAlgorithm> SignatureAlgorithm::CreateFromDer( 548 scoped_ptr<SignatureAlgorithm> SignatureAlgorithm::CreateFromDer(
549 const der::Input& algorithm_identifier) { 549 const der::Input& algorithm_identifier) {
550 der::Input oid; 550 der::Input oid;
551 der::Input params; 551 der::Input params;
552 if (!ParseAlgorithmIdentifier(algorithm_identifier, &oid, &params)) 552 if (!ParseAlgorithmIdentifier(algorithm_identifier, &oid, &params))
553 return nullptr; 553 return nullptr;
554 554
555 // TODO(eroman): Each OID is tested for equality in order, which is not 555 // TODO(eroman): Each OID is tested for equality in order, which is not
556 // particularly efficient. 556 // particularly efficient.
557 557
558 if (oid.Equals(der::Input(kOidSha1WithRsaEncryption))) 558 if (oid == der::Input(kOidSha1WithRsaEncryption))
559 return ParseRsaPkcs1(DigestAlgorithm::Sha1, params); 559 return ParseRsaPkcs1(DigestAlgorithm::Sha1, params);
560 560
561 if (oid.Equals(der::Input(kOidSha256WithRsaEncryption))) 561 if (oid == der::Input(kOidSha256WithRsaEncryption))
562 return ParseRsaPkcs1(DigestAlgorithm::Sha256, params); 562 return ParseRsaPkcs1(DigestAlgorithm::Sha256, params);
563 563
564 if (oid.Equals(der::Input(kOidSha384WithRsaEncryption))) 564 if (oid == der::Input(kOidSha384WithRsaEncryption))
565 return ParseRsaPkcs1(DigestAlgorithm::Sha384, params); 565 return ParseRsaPkcs1(DigestAlgorithm::Sha384, params);
566 566
567 if (oid.Equals(der::Input(kOidSha512WithRsaEncryption))) 567 if (oid == der::Input(kOidSha512WithRsaEncryption))
568 return ParseRsaPkcs1(DigestAlgorithm::Sha512, params); 568 return ParseRsaPkcs1(DigestAlgorithm::Sha512, params);
569 569
570 if (oid.Equals(der::Input(kOidEcdsaWithSha1))) 570 if (oid == der::Input(kOidEcdsaWithSha1))
571 return ParseEcdsa(DigestAlgorithm::Sha1, params); 571 return ParseEcdsa(DigestAlgorithm::Sha1, params);
572 572
573 if (oid.Equals(der::Input(kOidEcdsaWithSha256))) 573 if (oid == der::Input(kOidEcdsaWithSha256))
574 return ParseEcdsa(DigestAlgorithm::Sha256, params); 574 return ParseEcdsa(DigestAlgorithm::Sha256, params);
575 575
576 if (oid.Equals(der::Input(kOidEcdsaWithSha384))) 576 if (oid == der::Input(kOidEcdsaWithSha384))
577 return ParseEcdsa(DigestAlgorithm::Sha384, params); 577 return ParseEcdsa(DigestAlgorithm::Sha384, params);
578 578
579 if (oid.Equals(der::Input(kOidEcdsaWithSha512))) 579 if (oid == der::Input(kOidEcdsaWithSha512))
580 return ParseEcdsa(DigestAlgorithm::Sha512, params); 580 return ParseEcdsa(DigestAlgorithm::Sha512, params);
581 581
582 if (oid.Equals(der::Input(kOidRsaSsaPss))) 582 if (oid == der::Input(kOidRsaSsaPss))
583 return ParseRsaPss(params); 583 return ParseRsaPss(params);
584 584
585 if (oid.Equals(der::Input(kOidSha1WithRsaSignature))) 585 if (oid == der::Input(kOidSha1WithRsaSignature))
586 return ParseRsaPkcs1(DigestAlgorithm::Sha1, params); 586 return ParseRsaPkcs1(DigestAlgorithm::Sha1, params);
587 587
588 return nullptr; // Unsupported OID. 588 return nullptr; // Unsupported OID.
589 } 589 }
590 590
591 scoped_ptr<SignatureAlgorithm> SignatureAlgorithm::CreateRsaPkcs1( 591 scoped_ptr<SignatureAlgorithm> SignatureAlgorithm::CreateRsaPkcs1(
592 DigestAlgorithm digest) { 592 DigestAlgorithm digest) {
593 return make_scoped_ptr( 593 return make_scoped_ptr(
594 new SignatureAlgorithm(SignatureAlgorithmId::RsaPkcs1, digest, nullptr)); 594 new SignatureAlgorithm(SignatureAlgorithmId::RsaPkcs1, digest, nullptr));
595 } 595 }
(...skipping 19 matching lines...) Expand all
615 return nullptr; 615 return nullptr;
616 } 616 }
617 617
618 SignatureAlgorithm::SignatureAlgorithm( 618 SignatureAlgorithm::SignatureAlgorithm(
619 SignatureAlgorithmId algorithm, 619 SignatureAlgorithmId algorithm,
620 DigestAlgorithm digest, 620 DigestAlgorithm digest,
621 scoped_ptr<SignatureAlgorithmParameters> params) 621 scoped_ptr<SignatureAlgorithmParameters> params)
622 : algorithm_(algorithm), digest_(digest), params_(std::move(params)) {} 622 : algorithm_(algorithm), digest_(digest), params_(std::move(params)) {}
623 623
624 } // namespace net 624 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698